Closed aasmith closed 6 years ago
@aasmith , I was seeing this behaviour, and described it here https://github.com/steveklabnik/request_store/pull/25#issuecomment-160755460
More than that if you add something to request store in streamed view it will be not cleanup and next request will contain all "thread-local" variables
I believe this patch addresses the timing as to when the end of the request really occurs. However, if you are working with the request store inside one of the view fragments generated during view streaming, you have more work to do. The fragments are rendered inside a Fiber, which gets its own Thread.current. You would still need to pass the items you need from the existing Thread.current request store on to this new fiber, however that is outside of the scope for this patch/project maybe? This caveat only applies to view streaming, AFAIK.
Is there any plans to support merging this into master?
We're using this in production to fix an issue with streaming CSV downloads in ActiveAdmin, as referenced in https://github.com/activeadmin/activeadmin/issues/5115
Thanks!
I haven't looked at request_store
, in a while, but if this is an important patch for ActiveAdmin, I'm happy to :shipit: . Give me a bit.
Released as 1.4.0. Thanks everyone!
Thanks a ton!
When rendering a view with
render stream: true
the middleware clears the request store prematurely. This is because the request is considered complete shortly after the controller returns and not when all of the view fragments have been rendered. By wrapping the response in aRack::BodyProxy
, the middleware will instead clear out the request store after all of the streamed view is rendered and the body is complete.I'm not sure if this is a common enough use case to accommodate in this gem, but I thought it might be useful to have the discussion, as well as help anyone else who may be seeing this behavior.