Dynamic Images without WADocumentHandler

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Dynamic Images without WADocumentHandler

Ken Treis
I've got an application that needs to draw a graph, so I'm using Cairo  
to render it. This works really well. But I didn't realize until  
recently that code like this was problematic:

(html image)
        document: ws contents
        mimeType: 'image/png'

.. since it created WADocumentHandler instances that are never  
collected. I don't want these graphs to live forever in the image --  
they don't even need to be cached on the server, and they ought to be  
specific to a particular session. It's a similar situation to when I'm  
generating a CSV export of a client's data: the document is a one-time  
throw-away.

It seems like a callback is the right way to solve this (it's what I  
used in the CSV case too), so I hacked it together like so:

renderGraphOn: html
        (html image)
                class: 'graph';
                url: (html context actionUrl copy addParameter:
                                        (html callbacks registerCallback:
                                                        [self session respond:
                                                                        [:url |
                                                                        | ws |
                                                                        ws := ByteArray new writeStream.
                                                                        self writePngOn: ws.
                                                                        Seaside.WAResponse document: ws contents mimeType: 'image/
png']]))

This has the desired effect of linking the graph to the current  
session, and so far is appears to be free of the memory leak I was  
creating earlier using WADocumentHandler. Is this the right approach,  
or is there a better way? And if it's the right approach, can we add  
something like a #documentCallback: method to WAImageTag to make it  
easier to code things like this?

renderGraphOn: html
        (html image)
                class: 'graph';
                documentCallback:
                        [| ws |
                        ws := ByteArray new writeStream.
                        self writePngOn: ws.
                        Seaside.WAResponse document: ws contents mimeType: 'image/png']

--
Ken Treis
Miriam Technologies, Inc.

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside