chore: only invalidate vault user cache when required (#2519)
This commit is contained in:
@@ -179,7 +179,8 @@ export class VaultInviteService
|
||||
|
||||
this.removePendingInvite(pendingInvite.invite.uuid)
|
||||
|
||||
void this.sync.sync()
|
||||
this.sync.sync().catch(console.error)
|
||||
this.vaultUsers.invalidateVaultUsersCache(pendingInvite.invite.shared_vault_uuid).catch(console.error)
|
||||
|
||||
await this._decryptErroredPayloads.execute()
|
||||
|
||||
|
||||
@@ -12,16 +12,10 @@ import { AbstractService } from './../Service/AbstractService'
|
||||
import { VaultUserServiceEvent } from './VaultUserServiceEvent'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
import { IsVaultOwner } from './UseCase/IsVaultOwner'
|
||||
import { InternalEventInterface } from '../Internal/InternalEventInterface'
|
||||
import { InternalEventHandlerInterface } from '../Internal/InternalEventHandlerInterface'
|
||||
import { ApplicationEvent } from '../Event/ApplicationEvent'
|
||||
import { IsReadonlyVaultMember } from './UseCase/IsReadonlyVaultMember'
|
||||
import { IsVaultAdmin } from './UseCase/IsVaultAdmin'
|
||||
|
||||
export class VaultUserService
|
||||
extends AbstractService<VaultUserServiceEvent>
|
||||
implements VaultUserServiceInterface, InternalEventHandlerInterface
|
||||
{
|
||||
export class VaultUserService extends AbstractService<VaultUserServiceEvent> implements VaultUserServiceInterface {
|
||||
constructor(
|
||||
private vaults: VaultServiceInterface,
|
||||
private vaultLocks: VaultLockServiceInterface,
|
||||
@@ -47,20 +41,28 @@ export class VaultUserService
|
||||
;(this._leaveVault as unknown) = undefined
|
||||
}
|
||||
|
||||
async handleEvent(event: InternalEventInterface): Promise<void> {
|
||||
if (event.type === ApplicationEvent.CompletedFullSync) {
|
||||
this.vaults.getVaults().forEach((vault) => {
|
||||
async invalidateVaultUsersCache(sharedVaultUuid?: string) {
|
||||
if (sharedVaultUuid) {
|
||||
await this._getVaultUsers.execute({
|
||||
sharedVaultUuid: sharedVaultUuid,
|
||||
readFromCache: false,
|
||||
})
|
||||
void this.notifyEvent(VaultUserServiceEvent.InvalidatedUserCacheForVault, sharedVaultUuid)
|
||||
return
|
||||
}
|
||||
await Promise.all(
|
||||
this.vaults.getVaults().map(async (vault) => {
|
||||
if (!vault.isSharedVaultListing()) {
|
||||
return
|
||||
}
|
||||
this._getVaultUsers
|
||||
.execute({
|
||||
sharedVaultUuid: vault.sharing.sharedVaultUuid,
|
||||
readFromCache: false,
|
||||
})
|
||||
.catch(console.error)
|
||||
})
|
||||
}
|
||||
await this._getVaultUsers.execute({
|
||||
sharedVaultUuid: vault.sharing.sharedVaultUuid,
|
||||
readFromCache: false,
|
||||
})
|
||||
void this.notifyEvent(VaultUserServiceEvent.InvalidatedUserCacheForVault, vault.sharing.sharedVaultUuid)
|
||||
}),
|
||||
)
|
||||
void this.notifyEvent(VaultUserServiceEvent.InvalidatedAllUserCache)
|
||||
}
|
||||
|
||||
public async getSharedVaultUsersFromServer(
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export enum VaultUserServiceEvent {
|
||||
UsersChanged = 'VaultUserServiceEvent.UsersChanged',
|
||||
InvalidatedAllUserCache = 'VaultUserServiceEvent.InvalidatedUserCache',
|
||||
InvalidatedUserCacheForVault = 'VaultUserServiceEvent.InvalidatedUserCacheForVault',
|
||||
}
|
||||
|
||||
@@ -15,4 +15,5 @@ export interface VaultUserServiceInterface extends ApplicationServiceInterface<V
|
||||
leaveSharedVault(sharedVault: SharedVaultListingInterface): Promise<ClientDisplayableError | void>
|
||||
isVaultUserOwner(user: SharedVaultUserServerHash): boolean
|
||||
getFormattedMemberPermission(permission: string): string
|
||||
invalidateVaultUsersCache(sharedVaultUuid?: string): Promise<void>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user