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

extract keyCache from KeyLoaderFacade and UserFacade and handle user … #6925

Closed
wants to merge 1 commit into from

Conversation

bedhub
Copy link
Contributor

@bedhub bedhub commented May 8, 2024

…group key updates using a distribution key.

tutadb#1795

@bedhub bedhub added the model changes The code that was implemented to close this issue includes model changes and requires server release label May 8, 2024
* @param keyLoader a function to load and decrypt the group key if it is not cached
*/
getCurrentGroupKey(groupId: Id, keyLoader: () => Promise<VersionedKey>): Promise<VersionedKey> {
return getFromMap(this.currentGroupKeys, groupId, async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

if loader rejects you will have a cached rejected promise

const newCurrentGroupKeyCache = new Map<Id, Promise<VersionedKey>>()
for (const membership of user.memberships) {
const cachedGroupKey = this.currentGroupKeys.get(membership.group)
if (cachedGroupKey != null && Number(membership.groupKeyVersion) === (await cachedGroupKey).version) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if any of the cachedGroupKey reject the whole thing will fail

facade.setAccessToken("hello.")
facade.setUser({} as User)
o(facade.isPartiallyLoggedIn()).equals(true)
o(facade.isFullyLoggedIn()).equals(false)
})

o("updateUserGroupKey - successfull", function () {
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 have related tests it might be nice to put them in a spec()

Comment on lines +74 to +75
// @ts-ignore
o(cachedUserGroupKey.version).equals(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

rather than completely ts-ignoreing the line I would suggest to just unwrap it

Suggested change
// @ts-ignore
o(cachedUserGroupKey.version).equals(0)
o(cachedUserGroupKey!.version).equals(0)

@sarashub sarashub force-pushed the key-cache-1795 branch 2 times, most recently from 01ec221 to 1ec4628 Compare May 15, 2024 12:17
…group key updates using a distribution key.

tutadb#1795
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
model changes The code that was implemented to close this issue includes model changes and requires server release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants