pgte / alfred

Node is your mansion, Alfred is your butler. Node.js key-value store
http://pgte.github.com/alfred/
MIT License
149 stars 10 forks source link

Indicies not updated at end of EnsureIndex( ) fn resulting in failed find operations #7

Open davidthings opened 13 years ago

davidthings commented 13 years ago

In the following this code ( https://gist.github.com/952781 ) you will see I open a database, connect a key map, and ensure two indexes. Then I loop for five times creating an object then attempting to find it. This functions the first time - on a fresh database, but not on subsequent runs when the database contains data in it from a previous time. The records are not found via index, although they are there.

When I remove the reference to the second index (which is not being referred to in the code), all is well. Presumably because the index operations are done in a shorter time.

From this I concluded intially that although the object is added, the process of adding indicies was not complete by the time the function returns.

But now, I like an alternative hypothesis which is that the indicies are not completely loaded after the intial ensureIndex() call. Added a delay there fixes all subsequent loads and saves.