-
Notifications
You must be signed in to change notification settings - Fork 261
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
feat(event cache): handle linked chunk updates and reload in the sqlite backend #4340
Conversation
…lities This required adding support for *reading* out of the event cache, for the sqlite backend. This paves the way for the next PR (reload from the cache), and it should also help with testing at the `EventCacheStore` trait layer some day.
31a0a4b
to
e624870
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I see no blocker, I just have a couple of questions and one feedback for a possible improvement. Other than that, great!
crates/matrix-sdk-sqlite/migrations/event_cache_store/003_events.sql
Outdated
Show resolved
Hide resolved
-- Identifier of the chunk, unique per room. | ||
"id" INTEGER, | ||
-- Which room does this chunk belong to? (hashed key shared with the two other tables) | ||
"room_id" BLOB NOT NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just learned the difference between BLOB
and TEXT
in SQLite, but I wonder if we just not used a TEXT
here. According to this forum thread:
BLOBs cannot be searched, compared, or manipulated.
I think we want TEXT
here. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhuh, interesting. That suggests we may have issues when there are multiple rooms, then 👀 I'll do a few experiments and change it, if needs be — pretty sure we've been using that in other places too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pfew, https://sqlite.org/datatype3.html#sort_order says that BLOB are compared with memcmp
, so we're fine. I've added a test that used the same chunk identifier in two different rooms, and it passes, so it's all fine as is. We're using BLOB
in many many places, so if this should've failed, it would have failed elsewhere too ^^
So now, I do buy it that using TEXT
would offer us more, e.g. searching substrings, prefixes, etc. I don't think it's a useful use case for us, to search for a room id substring, be it in the clear or hashed.
Thanks for raising this, though! TIL 😌
"room_id" BLOB NOT NULL, | ||
|
||
-- The previous batch token of a gap (encrypted value). | ||
"prev_token" BLOB NOT NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we also want a TEXT
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a use case in mind where we'd need to search by prev_token
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to the other comment: no need to specify TEXT
unless we think we could need operations specific to a text object, which I don't think we need here either.
This was to make sure that we can search by blob.
bdefc0c
to
4b1e7e2
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4340 +/- ##
==========================================
+ Coverage 85.01% 85.08% +0.07%
==========================================
Files 275 275
Lines 30313 30487 +174
==========================================
+ Hits 25770 25940 +170
- Misses 4543 4547 +4 ☔ View full report in Codecov by Sentry. |
So, it's a bit of a chatty PR:
LinkedChunkBuilder
to recreate the full thing.Apart from that, the changes here are somewhat boring, and just running SQL requests.
I've taken the liberty to add a (clear) event id as a column for the events table, so we can add fetch_by_id easily in the future; this avoids a trivial migration.
Part of #3280
Split from #4308.