Title: [PATCH] Optimized PortletInstance creation

This patch minimizes object creation of PortletInstances by doing per-request caching on PortletInstance within the current HttpRequest.  PortletInstance's are keyed as "portlet_instance:<portlet id>".  I was prompted to do this not only because of the bug stated below, but because I counted, via a debugger, the same PortletInstance being instantiated no less than 7 seven times if not more (got tired of counting ;)!  Now it's down to once.

Bug fixed:
This also fixed a bug I was experiencing when minimizing/restoring portlets. 
After either of these actions I was required to refresh the screen to see the expected effect, basically causing the portlet to re-read its state from the profile.  I attributed this to too many instances of the same portlet instances floating around and being out of sync. The attached patch has also fixed this.

Scott

 

Index: JetspeedPortalPersistenceService.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/services/persistence/JetspeedPortalPersistenceService.java,v
retrieving revision 1.1
diff -u -r1.1 JetspeedPortalPersistenceService.java
--- JetspeedPortalPersistenceService.java       1 Jul 2002 04:30:24 -0000       1.1
+++ JetspeedPortalPersistenceService.java       1 Oct 2002 19:10:29 -0000
@@ -121,7 +121,21 @@
      */
     public PortletInstance getInstance(Portlet portlet, RunData data)
     {
-         return new JetspeedPortletInstance(portlet, data);
+       String attrKey = "portlet_instance:"+portlet.getID();
+       // optimize portlet instance retreival by saving it to the request
+       // this also guarantees the PortletInstance object is the same
+       // object for the entire life of the request
+       PortletInstance instance = (PortletInstance) 
+data.getRequest().getAttribute(attrKey);
+       if(instance != null)
+       {
+               return instance;
+       }
+       else
+       {
+               instance=  new JetspeedPortletInstance(portlet, data);
+               data.getRequest().setAttribute(attrKey, instance);
+               return instance;
+       }
     }
 
     /**

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to