-
Notifications
You must be signed in to change notification settings - Fork 289
fix(event cache): don't remove a gap when it's the only chunk in memory #4779
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5cd057a
chore(event cache): add spans for RoomEventCache methods
bnjbvr 905d4fe
chore(event cache): don't make use of `.not()` when it's not useful
bnjbvr 2b8d6d0
fix(event cache): don't try to remove a previous gap if it's the only…
bnjbvr b4f582d
test(event cache): double-check cascading happened in the clear linke…
bnjbvr 3e08056
refactor(event cache): call clear() instead of doing it manually in `…
bnjbvr 2db8a7c
fix(event cache): enable foreign keys on a connection basis
bnjbvr b60736c
feat(sdk): don't trigger the ignored user list change if it hasn't ch…
bnjbvr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,15 @@ impl SqliteEventCacheStore { | |
} | ||
|
||
async fn acquire(&self) -> Result<SqliteAsyncConn> { | ||
Ok(self.pool.get().await?) | ||
let connection = self.pool.get().await?; | ||
|
||
// Per https://www.sqlite.org/foreignkeys.html#fk_enable, foreign key support must be | ||
// enabled on a per-connection basis. Execute it every time we try to get a | ||
// connection, since we can't guarantee a previous connection did enable | ||
// it before. | ||
connection.execute_batch("PRAGMA foreign_keys = ON;").await?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
Ok(connection) | ||
} | ||
|
||
fn map_row_to_chunk( | ||
|
@@ -302,6 +310,9 @@ async fn run_migrations(conn: &SqliteAsyncConn, version: u8) -> Result<()> { | |
return Ok(()); | ||
} | ||
|
||
// Always enable foreign keys for the current connection. | ||
conn.execute_batch("PRAGMA foreign_keys = ON;").await?; | ||
|
||
if version < 1 { | ||
// First turn on WAL mode, this can't be done in the transaction, it fails with | ||
// the error message: "cannot change into wal mode from within a transaction". | ||
|
@@ -322,9 +333,6 @@ async fn run_migrations(conn: &SqliteAsyncConn, version: u8) -> Result<()> { | |
} | ||
|
||
if version < 3 { | ||
// Enable foreign keys for this database. | ||
conn.execute_batch("PRAGMA foreign_keys = ON;").await?; | ||
|
||
conn.with_transaction(|txn| { | ||
txn.execute_batch(include_str!("../migrations/event_cache_store/003_events.sql"))?; | ||
txn.set_db_version(3) | ||
|
@@ -1915,6 +1923,27 @@ mod tests { | |
let chunks = store.load_all_chunks(room_id).await.unwrap(); | ||
assert!(chunks.is_empty()); | ||
|
||
// Check that cascading worked. Yes, sqlite, I doubt you. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How dare you? |
||
store | ||
.acquire() | ||
.await | ||
.unwrap() | ||
.with_transaction(|txn| -> rusqlite::Result<_> { | ||
let num_gaps = txn | ||
.prepare("SELECT COUNT(chunk_id) FROM gaps ORDER BY chunk_id")? | ||
.query_row((), |row| row.get::<_, u64>(0))?; | ||
assert_eq!(num_gaps, 0); | ||
|
||
let num_events = txn | ||
.prepare("SELECT COUNT(event_id) FROM events ORDER BY chunk_id")? | ||
.query_row((), |row| row.get::<_, u64>(0))?; | ||
assert_eq!(num_events, 0); | ||
|
||
Ok(()) | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
// It's okay to re-insert a past event. | ||
store | ||
.handle_linked_chunk_updates( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It may be a good use case for
update_if
here, though it's not blocking the approval of this patch.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.
think
update_if
would trigger an update the first time it's set to a non default value, right? or we'd need to initialize theignore_user_list_changes
with an initial value without having it trigger, or something? might be nice actually, but yeah, follow up