Hey All,
I have a couple of problems that I have solved with recursive map reduce. I wanted to float the scenarios here in case there is something much better I should be doing. These problems may be better solved with something like Neo4J but I can keep the whole app in RavenDB for now that would be a big win.
Our application has a nested folder structure - currently we model it as one document per folder and folders point to their parent folder.
Scenario 1:
User permissions are inherited down the folder hierarchy. We have a recursive map reduce that sets each folder's computed permissions to the computed permissions of it's parent + it's own permissions. If a user is added at the top of the hierarchy the changes are propagated down one level at a time. Currently the computed permissions are stored in a companion document to avoid conflicts with the application editing the document but we are considering moving them to the document metadata so they can be used similarly to the permissions in the authorization bundle. So far performance seems. We are load testing right now and they permissions can get behind when inserting a large number of folders but under normal conditions it all looks good.
Scenario 2:
When we display a folder we want to enable breadcrumbs all the way to the top. In order to facilitate this we have a folder path property which is updated in a trigger. Once again if the user changes the name of a folder higher in the hierarchy the change propagates down and we append the current folder's name to the end.
So my questions are:
1. Is there some other way to model the information that would avoid these recursive map reduce updates? I've browsed some older posts that were related to this but couldn't find a design that seemed better. We are talking about large number of folders (10,000+) nested up to 10 levels deep so the solutions that suggested storing the hierarchy in one document probably won't work for me.
2. Is there a more elegant way to solve this? I would love if these properties could be computed in an index without the extra step of writing out a document but I understand that you need to write to a document in the trigger to the next recursion.
3. Should I be trying to solve this in my application somehow? I couldn't work out how to do this without running into race conditions if documents are being editing/indexes updated at the same time as I am querying for documents to update.
3. How commonly are people using recursive map/reduce in RavenDB? - I haven't found too many examples around the web.
If the answer to my questions is that this is a good idea and I'm on the right track I'll make sure to extract some stand alone examples in case they are helpful to others here.
cheers
Andrew Browne
Picnic Software