Skip to content
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

V2 Conversation Database #1150

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

nplasterer
Copy link
Contributor

@nplasterer nplasterer commented Oct 17, 2024

We need to store v2 conversations in the V3 database so that we can easily look up to see if a group dm should be shown or not.

@nplasterer nplasterer self-assigned this Oct 17, 2024
Copy link

graphite-app bot commented Oct 17, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

use super::Sqlite;
use super::{
db_connection::DbConnection,
schema::consent_records::{self, dsl},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement incorrectly references consent_records instead of v2_conversations. To align with the table being used in this file, please update the import to:

schema::v2_conversations::{self, dsl},

This change will ensure proper access to the correct table schema and avoid potential compilation errors or runtime issues.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

xmtp_mls/src/storage/encrypted_store/v2_conversation.rs Outdated Show resolved Hide resolved
@nplasterer nplasterer marked this pull request as ready for review October 18, 2024 16:58
@nplasterer nplasterer requested a review from a team as a code owner October 18, 2024 16:58
topic TEXT NOT NULL PRIMARY KEY,
created_at_ns BIGINT NOT NULL,
peer_address TEXT NOT NULL,
envelope_bytes BLOB NOT NULL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most expensive thing about listing v2 conversations is decrypting this envelope.

What if we actually stored the plaintext here so it only has to happen once?

pub fn insert_or_replace_v2_conversation(&self, v2_conversation: StoredV2Conversation) -> Result<StoredV2Conversation, StorageError> {
tracing::info!("Trying to insert v2 conversation");
let stored_v2_conversation = self.raw_query(|conn| {
let maybe_inserted_conversation: Option<StoredV2Conversation> = diesel::insert_into(dsl::v2_conversations)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is using on_conflict_do_nothing then it's actually an "insert or ignore" not an "insert or replace"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a helpful Diesel helper function insert_or_ignore_into


if maybe_inserted_conversation.is_none() {
let existing_conversation: StoredV2Conversation = dsl::v2_conversations.find(v2_conversation.topic).first(conn)?;
if existing_conversation.topic == v2_conversation.topic {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are looking this up by topic, I don't see why you would need this check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants