rdebusscher / AdvancedGraphicImageRenderer

Advanced PrimeFaces Graphic Image renderer for dynamic content
0 stars 6 forks source link

Release 1.0.0 also leaks tmp files on refresh of page due to renderer #4

Open 99sono opened 9 years ago

99sono commented 9 years ago

HI,

The process by which the renderer generates a unique id on the 1.0.0 branch also leaks to tmp file leakage, where each referesh of the page will lead for a new RID to be produced for an empty file.

I've presently fixed this by doing the following. String id = String.format("%1$s_%2$s", image.getClientId(), image.getValueExpression("value") .getExpressionString()); String rid = String.valueOf(id.hashCode());

rdebusscher commented 9 years ago

Not using the hashCode but the StringEncrypter utility class which is also used from PrimeFaces 4.x on. (copied from PrimeFaces 4.x as not present in 3.4 and 3.5)

99sono commented 9 years ago

In the end the original expression that I proposed for generating the Id based on clientId and value expression revealed itself not to be good enough because it is too deterministic for a given veiw. I the head of the code branch you will see that these two elements are used to create a CanonIcal ID. The final ID that is sent to the browser ends up being a combination of the canonical ID plus a random seed which changes with every deploymend plus an increment number. The incrementing number goes up each time a new StreamContent is open, and keeps the old number when the stream content is closed. When you have an ID generated in such a way, you get the following: If the user refreshes the page, the algorithm is able to generate the exact same ID that it had generated before, so it can continue feeding out the stream content to the temporary image the use is already seeing on the browser. However, if the user for example, uploads a new image and a new stream cotent is opened than the value of the ID changes. This is a proper solution as it ensures: (1) by having a random seed, with each new deployment you will be usind ids that are different than on the previous deployment and you survive the browser cache. (2) By hacing the client ID based Id, you can generate a unique Id number for each ID component - canonical id. You are also have in each deployment a way of deterministically knowing how ids are generated for each component, and mange the image resources created. (3) Finally, By having a map of the form CanonicalId -> ImageNrToGenerate map, you are also able to whenever needed produce a new unique image id for the stream cotent - if the user has changed the stream cotent - or re-use the old temporary image saved in the TMP folder if the user is for example refreshing. So we get the benefits of having uniqueness to by pass browser cache for images, and the advantage of having determinism for properly handling events such as page refresh or early cleanup of the TMP folder when a new image content is uploaded to replace the stream cotent that is associated to ui component whose previous stream content is now stale.

99sono commented 9 years ago

When I was using the clientId_expression to generate the id and faced the problem on the page refresh, then the following was the commit that fixed the issue.

https://github.com/99sono/AdvancedGraphicImageRenderer/commit/aaef57d977b5a2ee4710c2b07a34499357cff61a

Where the following method kind of illustrates the fix mentioned in the above post.

''' private String getCurrentUniqueId(String canonicalUniqueId) {