-
Notifications
You must be signed in to change notification settings - Fork 23
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
Conversation Sitching #1432
Merged
Merged
Conversation Sitching #1432
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
5938aeb
migration
codabrink b250d02
Fill the column
codabrink 334c066
wip
codabrink 9b894b5
adjust column
codabrink 7d1f8d9
adjust default
codabrink 13031f8
efficient derivation
codabrink 95639d9
use a trait
codabrink 865506d
fix the migration
codabrink 1438028
minor fixes
codabrink 91388a7
update welcome
codabrink 1873e99
use the concrete type
codabrink e4e2e87
cleanup
codabrink eb44a15
Merge branch 'main' into coda/stitching
codabrink 825b83f
remove the builder
codabrink d4d3d30
Merge branch 'coda/stitching' of github.com:xmtp/libxmtp into coda/st…
codabrink 037b8de
update the query
codabrink d155744
comment
codabrink 0f5c726
subquery
codabrink be69a8d
need those inbox ids to be different
codabrink e7f933b
test
codabrink 4c72ddc
cleanup
codabrink 9cefbc5
cleanup
codabrink 17f534e
lint
codabrink 75c9f0d
Update xmtp_mls/migrations/2024-12-18-170645_add_dm_id/up.sql
codabrink 3dfef1f
better test
codabrink fa4c810
test the timestamp
codabrink 55644b8
cleanup
codabrink 4959fbe
move comment
codabrink e820767
more cleanup
codabrink a287b35
test it
codabrink e70abb2
Merge remote-tracking branch 'origin/main' into coda/stitching
codabrink 5477865
wasm
codabrink 14693de
Merge remote-tracking branch 'origin/main' into coda/stitching
codabrink b234f27
test fix
codabrink 918d9da
test fix
codabrink c8c6f5b
Merge branch 'main' into coda/stitching
codabrink 3dbcd67
fix migration headaches
codabrink 70ac2b4
fix
codabrink ab0acf1
lint
codabrink f375274
add option to include duplicate dms
codabrink 9ed24e7
Merge remote-tracking branch 'origin/main' into coda/stitching
codabrink 04ad4ed
lint
codabrink 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 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 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 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 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 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 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 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
2 changes: 1 addition & 1 deletion
2
xmtp_mls/migrations/2024-12-20-143210_create_conversation_list_view/down.sql
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
DROP VIEW IF EXISTS conversation_list; | ||
DROP VIEW IF EXISTS conversation_list; |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE groups DROP COLUMN dm_id; | ||
ALTER TABLE groups DROP COLUMN last_message_ns; | ||
ALTER TABLE groups ADD COLUMN dm_inbox_id TEXT; | ||
|
||
DROP TRIGGER IF EXISTS msg_inserted; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
DROP VIEW IF EXISTS conversation_list; | ||
ALTER TABLE groups ADD COLUMN dm_id TEXT; | ||
ALTER TABLE groups ADD COLUMN last_message_ns BIGINT; | ||
|
||
-- Fill the dm_id column | ||
UPDATE groups | ||
SET dm_id = 'dm:' || | ||
LOWER( | ||
CASE | ||
WHEN LOWER((SELECT inbox_id FROM identity)) < LOWER(dm_inbox_id) | ||
THEN (SELECT inbox_id FROM identity) || ':' || dm_inbox_id | ||
ELSE dm_inbox_id || ':' || (SELECT inbox_id FROM identity) | ||
END | ||
) | ||
WHERE dm_inbox_id IS NOT NULL; | ||
|
||
DROP INDEX IF EXISTS idx_dm_target; | ||
ALTER TABLE groups DROP COLUMN dm_inbox_id; | ||
|
||
-- Create a trigger to auto-update group table on insert | ||
CREATE TRIGGER msg_inserted | ||
AFTER INSERT ON group_messages | ||
BEGIN | ||
UPDATE groups | ||
SET last_message_ns = (strftime('%s', 'now') * 1000000000) + (strftime('%f', 'now') * 1000000) | ||
WHERE id = NEW.group_id; | ||
END; | ||
|
||
|
||
CREATE VIEW conversation_list AS | ||
WITH ranked_messages AS ( | ||
SELECT | ||
gm.group_id, | ||
gm.id AS message_id, | ||
gm.decrypted_message_bytes, | ||
gm.sent_at_ns, | ||
gm.kind AS message_kind, | ||
gm.sender_installation_id, | ||
gm.sender_inbox_id, | ||
gm.delivery_status, | ||
gm.content_type, | ||
gm.version_major, | ||
gm.version_minor, | ||
gm.authority_id, | ||
ROW_NUMBER() OVER (PARTITION BY gm.group_id ORDER BY gm.sent_at_ns DESC) AS row_num | ||
FROM | ||
group_messages gm | ||
WHERE | ||
gm.kind = 1 | ||
) | ||
SELECT | ||
g.id AS id, | ||
g.created_at_ns, | ||
g.membership_state, | ||
g.installations_last_checked, | ||
g.added_by_inbox_id, | ||
g.welcome_id, | ||
g.dm_id, | ||
g.rotated_at_ns, | ||
g.conversation_type, | ||
rm.message_id, | ||
rm.decrypted_message_bytes, | ||
rm.sent_at_ns, | ||
rm.message_kind, | ||
rm.sender_installation_id, | ||
rm.sender_inbox_id, | ||
rm.delivery_status, | ||
rm.content_type, | ||
rm.version_major, | ||
rm.version_minor, | ||
rm.authority_id | ||
FROM | ||
groups g | ||
LEFT JOIN ranked_messages rm | ||
ON g.id = rm.group_id AND rm.row_num = 1 | ||
ORDER BY COALESCE(rm.sent_at_ns, g.created_at_ns) DESC; |
This file contains 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 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.
Had to recreate the view to account for the column rename
dm_inbox_id
->dm_id