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

Private Preferences DB #946

Merged
merged 14 commits into from
Sep 10, 2024
Merged

Conversation

nplasterer
Copy link
Contributor

Part of #801

Adds a new table for personal preference records in the local db

@nplasterer nplasterer self-assigned this Aug 7, 2024
Copy link
Contributor Author

@nplasterer nplasterer left a comment

Choose a reason for hiding this comment

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

@xmtp/engineering would love some preliminary heads thinking about this data structure for personal preferences. 🙏

@@ -0,0 +1,11 @@
CREATE TABLE "private_preferences"(
-- The inbox_id the private preferences are owned by
"inbox_id" text NOT NULL,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We might not need an inbox_id since every item in this list will be for the person who is logged in they shouldn't be getting other peoples preferences.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds right. The entire DB is scoped to a single inbox

-- The value of what has a preference
"value" text NOT NULL,
PRIMARY KEY (valueType, value)
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Want to make sure I'm reasoning about this correctly we will want a way to get the current consent state for a group or inbox id performantly so the primary key should be the value and the valueType so that you can fetch for type group and value group_id and get what the state is.

Copy link
Contributor

Choose a reason for hiding this comment

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

That does feel like what we'll want at the end of the process. Very cheap to look up, has all the information a

One thing that was a struggle in the past is just making sure that we processed all the events in the correct order, so that if you allowed and then blocked the same group you'd get a consistent value in the end. What happens if you received a preferences event that you couldn't read before, but now you can? How do we rewind things so that you can rebuild the state? Maybe the right answer is to truncate this table and start from scratch in that scenario?

Copy link
Contributor

@insipx insipx Sep 6, 2024

Choose a reason for hiding this comment

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

does it make sense to make an index here, like we did for inbox id?

CREATE INDEX idx_value_type_value ON private_preferences(valueType, value ASC);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that the primary key made an index by default so we shouldn't need to add another index.

-- The inbox_id the private preferences are owned by
"inbox_id" text NOT NULL,
-- Enum of the PRIVATE_PREFERENCE_TYPE (GROUP, INBOX, etc..)
"valueType" int NOT NULL,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we will want to have some logic in the code that says if type is ADDRESS find the inbox_id for that address and actually only store and fetch inbox ids. Probably a migration needed to convert all the V2 items to inbox ids.

@@ -0,0 +1,11 @@
CREATE TABLE "private_preferences"(
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we really want to call this "consent state".

Private preferences sounds more generic than what is really here. The schema is very specific to consent preferences (which is also the only kind we have right now).

-- Enum of PREFERENCE_STATE (ALLOWED, DENIED, etc..)
"state" int NOT NULL,
-- The value of what has a preference
"value" text 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.

What do we think about calling it the "entity" just for clarity. I could read value to mean either "the thing that has a preference" or "the preference itself".

@nplasterer nplasterer marked this pull request as ready for review September 6, 2024 21:30
@nplasterer nplasterer requested a review from a team as a code owner September 6, 2024 21:30
@insipx
Copy link
Contributor

insipx commented Sep 6, 2024

sans nits/lints + tests, it looks good to me

@nplasterer nplasterer requested review from insipx and a team September 10, 2024 03:10
@@ -150,8 +150,12 @@ impl TryFrom<DmMembersProto> for DmMembers {

fn try_from(value: DmMembersProto) -> Result<Self, Self::Error> {
Ok(Self {
member_one_inbox_id: value.dm_member_one.unwrap().inbox_id.clone(),
member_two_inbox_id: value.dm_member_two.unwrap().inbox_id.clone(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These unwraps were just on the mls_dms feature branch already. Just cleaning up the linter in this PR. cc @cameronvoell

@nplasterer nplasterer merged commit 7f3f0cf into mls-dm-release Sep 10, 2024
5 checks passed
@nplasterer nplasterer deleted the np/create-private-preference-db branch September 10, 2024 13:52
@nplasterer nplasterer mentioned this pull request Sep 11, 2024
nplasterer added a commit that referenced this pull request Oct 1, 2024
* Adds functions for creating a DM group (#901)

* update bindings cargo locks

* Added dm group functionality

* dm members can update all metadata

* fix tests

* fix indentation

* fix test imports

* gen protos back to main

---------

Co-authored-by: cameronvoell <[email protected]>

* Private Preferences DB (#946)

* create the database migration for the private preference work

* update the table to be focused on consent

* first pass at database storage structure

* update the get method for consent records

* fix up the set method

* add a test

* fix up the test

* fix up the clippy error with consent record

* fix up the clippy error with consent record

* fix up all clippy issues

* cargo fmt

* Validate dm group metadata + permissions from welcome (#1075)

* validate dm group before creating from welcome

* lint fix

* lint fix

---------

Co-authored-by: cameronvoell <[email protected]>

* fixes after merge

* DM updates - default to not displaying dm groups (#1046)

* bindings create_dm function

* find groups by default does not include dm groups

* fmt fix

* dont execute callbacks when dm group welcomes are streamed

* Update bindings_ffi/src/mls.rs

Co-authored-by: Andrew Plaza <[email protected]>

* fixed bad merge

* filter dms in stream_conversations

* surface include_dm_groups in bindings list function more clearly

---------

Co-authored-by: cameronvoell <[email protected]>
Co-authored-by: Andrew Plaza <[email protected]>

* fix merge conflicts

* cargo clippy

* Remove tracing from test

* Fix test

* try and fix the tests

* fix up the test

---------

Co-authored-by: cameronvoell <[email protected]>
Co-authored-by: Naomi Plasterer <[email protected]>
Co-authored-by: Andrew Plaza <[email protected]>
Co-authored-by: Ry Racherbaumer <[email protected]>
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.

3 participants