-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option for writable JSONStores (for single JSON files only). #507
Added option for writable JSONStores (for single JSON files only). #507
Conversation
Codecov Report
@@ Coverage Diff @@
## main #507 +/- ##
==========================================
+ Coverage 88.73% 88.76% +0.03%
==========================================
Files 40 40
Lines 2672 2689 +17
==========================================
+ Hits 2371 2387 +16
- Misses 301 302 +1
Continue to review full report at Codecov.
|
Thanks for this @davidwaroquiers! I think your solution is fine given the intended use cases for One thing I would vote to have is a tiny bit more text in the doc string description for |
Hello @munrojm , Thanks for your message. Indeed I can describe this in more details. I could also change the parameter to e.g. "write_to_file" or "file_update" or "file_writable" (or something else) that would make it more clear as well. What do you think ? Or just describing the behavior in the docstring is sufficient ? Best, David |
I think both of those things would be good! Once you update, I will merge and release. |
Updated docstring to make it more clear it only applies to the writing of the file (JSONStore behaves like a MemoryStore when file_writable is False). Updated tests accordingly. Added test to make sure the file is NOT updated when file_writable is False.
Done. I've also added one more test to make sure the file is not written when file_writable is False. |
Great, thanks for that. Once the new test passes I will merge. |
Ah... Sorry, this was working on my laptop ... so I tried again and indeed the test is sometimes passing sometimes failing... I should have known something like that could happen. Probably a thread/system issue. Not exactly sure how to deal with this. Also makes me wonder if my implementation of "update_json_file" is indeed thread-safe and if I should not lock the file while writing or something like this ... I will investigate this in more details. If you have any ideas/comments on how to deal with that issue, do not hesitate to share it with me :) |
called when file_writable is False.
Hi @munrojm |
Hi @davidwaroquiers, the test change looks good to me. Thanks for your thoughts on file locking. Given the intended use of the store, I agree with your sentiment and think the current solution is appropriate. Happy to merge now and deal with future thread safety concerns if they come up. Thanks again for this contribution! |
Added option to allow for a writable JSONStore. The default stays the same, i.e. the JSONStore is just a MemoryStore initialized from a json or a list of json files.
When a write-like operation is performed on the JSONStore (i.e. "update" or "remove_docs"), the json file is rewritten. This is of course not optimal if you have a large json file/database. Nonetheless, this is not meant to be used for large data but for small use cases.
Note that this option is not available when more than one json file is provided.
A unit test has been added.