nkohari / stash

A graph-based cache for Node.js, powered by Redis
http://nkohari.github.com/stash
Other
49 stars 2 forks source link

Deleting a parent entity results in orphaned child entities. #1

Open ghost opened 12 years ago

ghost commented 12 years ago

Say I have a structure where post1 is dependent on comment1, comment2, and comment3.

My idea would be to mark certain entities as delete-if-orphaned, and, when an entity depending on them is deleted/invalidated, they would also be removed. Not sure if that's the best way to go about this, though.

nkohari commented 12 years ago

Yeah, support for removing items is currently very half-baked. I added rem() primarily to clean up my test teardown methods, but realized there would probably be value in keeping it in.

The problem with removing nodes in general is that in the current master there are only unidirectional edges between nodes, pointing from "child" nodes to "parent" nodes. As such, a node is only aware of things that are dependent on itself, but isn't aware of things it depends on. When a node is removed entirely from the graph, the correct thing to do is to remove any edges going to it, but right now there isn't enough information to do that.

To fix this problem, I'm currently working on adding bidirectional links defining edges between nodes. Rather than <id>:deps keys, there will be <id>:out and <id>:in keys. Once this exists, rem() will be more useful.

Adding support for delete-if-orphaned is interesting, but I'd have to put some more thought into it. It strikes me as possibly being very expensive.