Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion keeperapi/src/syncDown/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type DKdFolder = {
export type DKdFolderAccess = {
kind: 'keeper_drive_folder_access'
accessUid: string
uid: string
folderUid: string
accessTypeUid: string
accessType: Folder.AccessType
accessRoleType: Folder.AccessRoleType
Expand Down
23 changes: 18 additions & 5 deletions keeperapi/src/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,14 @@ export type Dependency = {
parentUid: string
uid: string
}
export type RemovedDependency = {
parentKind: VaultStorageKind
childKind: VaultStorageKind
childUid: string
}
export type DependencyMap = Record<string, Dependency>
export type Dependencies = Record<string, Set<Dependency>>
export type RemovedDependencies = Record<string, Set<string> | '*'>
export type RemovedDependencies = Record<string, Set<string | RemovedDependency> | '*'>

const addDependencies = (dependencies: Dependencies, parentUid: string, childUid: string, kind: VaultStorageKind) => {
let children = dependencies[parentUid]
Expand All @@ -283,13 +288,17 @@ const addDependencies = (dependencies: Dependencies, parentUid: string, childUid
})
}

const addRemovedDependencies = (dependencies: RemovedDependencies, parentUid: string, childUid: string) => {
const addRemovedDependencies = (
dependencies: RemovedDependencies,
parentUid: string,
childUid: string | RemovedDependency
) => {
let children = dependencies[parentUid]
if (children === '*') {
return
}
if (!children) {
children = new Set<string>()
children = new Set<string | RemovedDependency>()
dependencies[parentUid] = children
}
children.add(childUid)
Expand Down Expand Up @@ -1192,7 +1201,7 @@ const processKdFolderAccesses = async (
await storage.put({
kind: 'keeper_drive_folder_access',
accessUid: createKdFolderAccessCompositeKey(accessTypeUid, folderUid),
uid: folderUid,
folderUid,
accessTypeUid,
accessType: folderAccess.accessType,
accessRoleType: folderAccess.accessRoleType,
Expand Down Expand Up @@ -1401,7 +1410,11 @@ const processKdRemovedFolderRecords = (
if (!folderRecord.recordUid || !folderRecord.folderUid) continue
const recordUid = webSafe64FromBytes(folderRecord.recordUid)
const folderUid = webSafe64FromBytes(folderRecord.folderUid)
addRemovedDependencies(removedDependencies, folderUid, recordUid)
addRemovedDependencies(removedDependencies, folderUid, {
parentKind: 'keeper_drive_folder',
childKind: 'record',
childUid: recordUid,
})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

❓ Why do we need this?

When a KD folder is removed, all its child resources should be wiped altogether. However, since the delete operation takes place before the dependency removal, when the record is removed from the folder, the folder data is already cleaned up and the consumer app fails to identify the kind based off of the uid. This will remove the burden of consumer apps figuring out the resource type out of the uid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is such a good idea that it's maybe worth making this a breaking change (rather than string | RemovedDependency, make children just a set of RemovedDependency). The guessing we have to do on the BE side is no fun and probably caused some bugs. Something to consider (of course all the other dependency additions would have to be updated)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah just wanted to avoid big changes. I'll create a Jira ticket for this tho https://keeper.atlassian.net/browse/BE-7544.

}
}

Expand Down
Loading