-
Notifications
You must be signed in to change notification settings - Fork 552
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
Allow Table.get by doc_id to have O(1) behavior #460
Conversation
6455c6b
to
e31f232
Compare
Important note: I finally had a chance to test this locally in application and |
OK the problem seems to be inside actions/checkout. It is putting the head of master into the runner for testing instead of this PR's code, see here. And the resulting git log checkout is 967dbf9 which is an existing commit (currently master:HEAD). This is super weird. The checkout command should be /usr/bin/git checkout --progress --force refs/remotes/pull/{PRnum}/merge A little more research shows that this is an effect of triggering the CI runs from I've put this mess into another PR #462 and will reset this one to a simpler commit reflecting the original purpose, but hopefully not broken. |
2611837
to
9312ecd
Compare
Thanks @richardsheridan, I expect to have a look at this soon 🙂 |
9312ecd
to
d082bc6
Compare
Great work @richardsheridan, I really appreciate it! Reading through your PR and then through TinyDB's code I even found that we can skip converting most document IDs for A futher note: There was a question in #459 (since moved to #466) that notes that one could skip the opposite document ID conversion, namely converting document IDs to string during write operations. However, as there are some storages that silently convert |
By the way, I'll try to get a release of TinyDB that contains this change published the next weekend or next week. |
Awesome! I'm so happy to have contributed to the only database I may ever use :) |
Table.get
is accidentallyO(len(Table))
because of the conversion ofdoc_id
inTable._read_table
. However, in the few places_read_table
is used, there are opportunities to convert locally. Indeed, I discovered thatTable._get_next_id
was redundantly converting them already. Converting the user-inputdoc_id
to string just before doing thedict.get
call makes the overall lookupO(1)
.Also this change permits a bit of code sharing with(nope)Table._update_table
.Of course, reading from the underlying storage is more like
O(nTables*avgLenTables)
in the standard case, so any speedup would only be realized when usingCachingMiddleware
or the like.Looking forward to seeing if this passes the test suite! 😅