[JAVA-4444] Support user contexts in the encoder / decoder contexts Created: 14/Jan/22 Updated: 27/Oct/23 Resolved: 02/Feb/22 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Unknown |
| Reporter: | Ross Lawley | Assignee: | Jeffrey Yemin |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
See: PR: https://github.com/mongodb/mongo-java-driver/pull/846
|
| Comments |
| Comment by PM Bot [ 02/Feb/22 ] |
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information. |
| Comment by Justin Lee [ 18/Jan/22 ] |
|
I'm not sure I would agree at this point. If I have to go the route of opening and closing a cache around a query/aggregation, there's no immediate need to tie that to the DecoderContext necessarily. I can just use a simple Service Lookup pattern to find that cache. That still leaves the case of tracking the type of a query/aggregation for resolving source types but maybe I don't really need those. Let me play with that cache idea and we'll circle back to this one. |
| Comment by Jeffrey Yemin [ 18/Jan/22 ] |
|
I don't have any bright ideas here, but it sounds like the particular change requested here is not going to accomplish your goal. Would you agree? And if so, I suggest we close this and open a new ticket if you can think of a different driver enhancement that would help. |
| Comment by Justin Lee [ 14/Jan/22 ] |
|
When loading a reference, I would like consult/update a cache so that a referenced document is only loaded the once. Among other things, this would enable circular references (there was a recent bug report about that) but would also obviously reduce the amount of processing in general. So when decoding a document and I encounter a referenced entity, I can begin to cache those to short circuit any further references in the results. Now, if the context gets recreated with each document in the result set, that poses a problem. I suppose the simplest, and therefore probably the wrong, answer is to use a ThreadLocal cache to wrap the decoding in a transaction-like boundary. e.g., in Morphia, I would register the cache in a ThreadLocal, execute the query/aggregation, and then deregister that cache to avoid reference leaks. A little less ideal but still tenable. Having this capability would also allow me to register the source type of an aggregation, say, to track mapping information for querying against references so that I know how to/if i need to encoded comparison values for those properties. |
| Comment by Jeffrey Yemin [ 14/Jan/22 ] |
|
Hi justin.lee Can you explain a bit how Morphia would make use this API? Since DecoderContext instances are created anew by the driver for each document being decoded how would Morphia take advantage of attachments that were added to a single instance of DecoderContext? It seems that any cache would have to be either a global, or configured at the level of MongoClient.
|