-
Notifications
You must be signed in to change notification settings - Fork 57
Deduplicate client registrations by hashing the metadata #4293
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
Deploying matrix-authentication-service-docs with
|
Latest commit: |
3f66940
|
Status: | ✅ Deploy successful! |
Preview URL: | https://5800f4a7.matrix-authentication-service-docs.pages.dev |
Branch Preview URL: | https://quenting-client-reg-dedupe.matrix-authentication-service-docs.pages.dev |
93fbb4f
to
b4ceb00
Compare
This is done by using the indexmap crate to preserve insertion order for localized fields.
f5b609e
to
4294dc8
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.
seems good otherwise
pub struct Localized<T> { | ||
non_localized: T, | ||
localized: HashMap<LanguageTag, T>, | ||
localized: IndexMap<LanguageTag, T>, |
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.
why not use a BTreeMap, which sorts by key order?
I'm just thinking the clients might be sending requests with HashMaps on their end, so key order on the wire is not guaranteed to be stable.
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.
Because LanguageTag
doesn't implement Ord
, so I can't use a BTreeMap :(
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'm just thinking the clients might be sending requests with HashMaps on their end, so key order on the wire is not guaranteed to be stable.
Sure, but that's on them. The deduplication is a best-effort thing anyway 🤷
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.
Hmm, I take what you mean, but I'm still not a fan of introducing some fun nondeterminism (even if it's the client's fault) even if it is just a 'best-effort' (or worst-effort as my supervisor liked to say) thing.
Can we maybe call .sort_by(|k1, _, k2, _| k1.as_str().cmp(k2.as_str()))
on the IndexMap prior to serialising for hashing?
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.
(or cheeky-PR a Ord impl to language_tags
;-))
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 added a sort on all the Localized<T>
and Vec<T>
properties in 3f66940
This deduplicates client registrations by hashing the client metadata, saving that hash in the database, and look for existing entries during registration.
This was relatively straightforward; I had although to make sure that the property order in the client metadata was stable, and therefore replaced the localized metadata hashmaps with indexmaps, which preserve insertion order.