Possible bug: Duplicate cache of same doc if updated inside Collection.after.insert
See original GitHub issueHi,
I’m using the matb33:collection-hooks
package.
It provides hooks like Collection.after.insert.
Suppose I have Questions
collection denormalized into Lectures
collection.
When I create a question “What’s up?”, the expected behaviour is for Lecture document to look like this:
// Lecture Document
_id: ....
questionsCache: [
{
_id: 5e44dRMouE9BiwgLP,
body: "What's up?"
}
]
However, suppose I have a after.insert hook in which I update that question, like this:
Questions.after.insert((userId, doc) => {
Questions.update({_id: doc._id}, {$set: {someFlag: true}});
})
When this is the case, this is what questionsCache
looks like instead:
// Lecture Document
_id: ....
questionsCache: [
{
_id: 5e44dRMouE9BiwgLP,
body: "What's up?"
},
{
_id: 5e44dRMouE9BiwgLP,
body: "What's up?",
someFlag: true
},
]
Is there perhaps a race condition going on, because the after.insert hook probably fires before the cache is registered?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Customizing the behavior of cached fields - Apollo GraphQL
An array of key arguments that help the cache avoid storing unnecessary duplicate data. You provide field policies to the constructor of InMemoryCache...
Read more >How the Document Cache Shape Works - Boomi Community
The doc cache is used in two distinct ways in the platform: Storing documents to look up information inside of the document based...
Read more >Chrome is incorrectly storing and sending duplicate cookies ...
(4) Another cookie update is received. This time, the update will cause us to insert a duplicate into the cookie database. This happens...
Read more >c# - Collection was modified; enumeration operation may not ...
Why this error? ... In general .Net collections do not support being enumerated and modified at the same time. If you try to...
Read more >db.collection.insert() — MongoDB Manual
If the document contains an _id field, the _id value must be unique within the collection to avoid duplicate key error. Transactions. db.collection.insert()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi! Grapher uses my denormalization package, which is actually built on Collection Hooks too. The order in which Collection Hooks run is determined by the order they were set up. You could try swapping the order you create the denormalization and set up your insert hook, or you could use my cacheField function, which is tested to work properly with the other cache types.
Cool. I’ll try 😃