I change tomato from a veggie to a fruit & i get an ADD to fruit, followed by a REMOVE from veggies from rethink (i treat the ADD as an upsert)
i call remove like remove({id: 'tomato', type: 'veggie'}). per the cashay API, every field provided by the remove object must match the entity in order to be removed. That way, when the ADD happens first, it changes type to fruit and when the remove occurs, the entity isn't actually removed, it's just spliced from the result array of food/veggies.
Here's the tricky part:
Currently, cashay compares the remove object {id: 'tomato', type: 'veggie'} to the denormalized result.
That denormalized still looks exactly like the remove object because when ADD was called we currently don't traverse over every single sub to figure out which ones contain that doc.
We can fix this in 2 ways:
Traverse every single denormalized result for every single subscription whenever we have an UPDATE. That is O(n) & sucks for things that have an update frequency < 1 second. Plus, detecting that it is an update is a bit tricky because the document only exists in entities, not in the result.
Run the comparison against the normalized result, not the denormalized result. This sucks less, but still sucks because that denormalized result, while it still exists, is showing something that is not accurate. (type: 'veggie'). For my use case, this doesn't really matter because that removal message should arrive very quickly, and even if it takes a few second, it'll just show 2 docs until the old one gets removed.
food/fruits
andfood/veggies
.ADD
to fruit, followed by aREMOVE
from veggies from rethink (i treat theADD
as an upsert)remove({id: 'tomato', type: 'veggie'})
. per the cashay API, every field provided by the remove object must match the entity in order to be removed. That way, when theADD
happens first, it changestype
tofruit
and when the remove occurs, the entity isn't actually removed, it's just spliced from the result array offood/veggies
.Here's the tricky part:
{id: 'tomato', type: 'veggie'}
to the denormalized result.ADD
was called we currently don't traverse over every single sub to figure out which ones contain that doc.We can fix this in 2 ways:
type: 'veggie'
). For my use case, this doesn't really matter because that removal message should arrive very quickly, and even if it takes a few second, it'll just show 2 docs until the old one gets removed.