-
Notifications
You must be signed in to change notification settings - Fork 554
Update driver cache entries to contain the file version #25337
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
base: main
Are you sure you want to change the base?
Changes from all commits
97e3aeb
7972883
a5f5ac5
dc402b0
72ba0bc
ae735ef
04c8817
5c814a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,7 +114,7 @@ export interface IPersistedCache { | |
put(entry: ICacheEntry, value: any): Promise<void>; | ||
|
||
/** | ||
* Removes the entries from the cache for given parametres. | ||
* Removes the entries from the cache for given parameters. | ||
* @param file - file entry to be deleted. | ||
*/ | ||
removeEntries(file: IFileEntry): Promise<void>; | ||
|
@@ -127,5 +127,24 @@ export interface IPersistedCache { | |
* @internal | ||
*/ | ||
export function getKeyForCacheEntry(entry: ICacheEntry): string { | ||
return `${entry.file.docId}_${entry.type}_${entry.key}`; | ||
const version = | ||
"fileVersion" in entry.file.resolvedUrl && entry.file.resolvedUrl.fileVersion !== undefined | ||
? `_${entry.file.resolvedUrl.fileVersion}` | ||
: ""; | ||
switch (entry.type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are both these functions used? they are both internal, so we should unify on one, probably this one, since the logic is odsp specific There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should also add unit test for the function, which should be pretty straight forward |
||
case snapshotWithLoadingGroupIdKey: | ||
case snapshotKey: { | ||
// example versioned entry: docId_4.0_snapshot_ | ||
// example non-versioned entry: docId_snapshot_ | ||
// The trailing '_' is included for consistency with existing cache entries | ||
return `${entry.file.docId}${version}_${entry.type}_`; | ||
} | ||
case "ops": { | ||
// example versioned entry: docId_4.0_ops_100_3 | ||
// example non-versioned entry: docId_ops_100_3 | ||
return `${entry.file.docId}${version}_${entry.type}_${entry.key}`; | ||
} | ||
default: | ||
return `${entry.file.docId}_${entry.type}_${entry.key}`; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { strict as assert } from "node:assert"; | ||
|
||
import { | ||
getKeyForCacheEntry, | ||
type CacheContentType, | ||
type ICacheEntry, | ||
type IOdspResolvedUrl, | ||
} from "@fluidframework/odsp-driver-definitions/internal"; | ||
|
||
function createMockCacheEntry( | ||
url: IOdspResolvedUrl, | ||
type: CacheContentType, | ||
key: string, | ||
): ICacheEntry { | ||
return { | ||
type, | ||
key, | ||
file: { | ||
resolvedUrl: url, | ||
docId: "test-doc-id", | ||
}, | ||
}; | ||
} | ||
|
||
// Define both cache entry types here for readability | ||
const opType = "ops"; | ||
const snapshotType = "snapshot"; | ||
|
||
describe("getKeyForCacheEntry", () => { | ||
const odspResolvedUrlWithoutVersion: IOdspResolvedUrl = { | ||
type: "fluid", | ||
odspResolvedUrl: true, | ||
id: "1", | ||
siteUrl: "fakeUrl", | ||
driveId: "1", | ||
itemId: "1", | ||
url: "fakeUrl", | ||
hashedDocumentId: "1", | ||
endpoints: { | ||
snapshotStorageUrl: "fakeUrl", | ||
attachmentPOSTStorageUrl: "fakeUrl", | ||
attachmentGETStorageUrl: "fakeUrl", | ||
deltaStorageUrl: "fakeUrl", | ||
}, | ||
tokens: {}, | ||
fileName: "fakeName", | ||
summarizer: false, | ||
fileVersion: undefined, | ||
}; | ||
|
||
const odspResolvedUrlWithVersion: IOdspResolvedUrl = { | ||
type: "fluid", | ||
odspResolvedUrl: true, | ||
id: "1", | ||
siteUrl: "fakeUrl", | ||
driveId: "1", | ||
itemId: "1", | ||
url: "fakeUrl", | ||
hashedDocumentId: "1", | ||
endpoints: { | ||
snapshotStorageUrl: "fakeUrl", | ||
attachmentPOSTStorageUrl: "fakeUrl", | ||
attachmentGETStorageUrl: "fakeUrl", | ||
deltaStorageUrl: "fakeUrl", | ||
}, | ||
tokens: {}, | ||
fileName: "fakeName", | ||
summarizer: false, | ||
fileVersion: "3.0", | ||
}; | ||
|
||
it("creates a non-versioned snapshot cache entry", () => { | ||
const entry = createMockCacheEntry(odspResolvedUrlWithoutVersion, snapshotType, ""); | ||
const key = getKeyForCacheEntry(entry); | ||
assert.equal(key, "test-doc-id_snapshot_"); | ||
}); | ||
it("creates a versioned snapshot cache entry", () => { | ||
const entry = createMockCacheEntry(odspResolvedUrlWithVersion, snapshotType, ""); | ||
const key = getKeyForCacheEntry(entry); | ||
assert.equal(key, "test-doc-id_3.0_snapshot_"); | ||
}); | ||
|
||
it("creates a non-versioned op cache entry", () => { | ||
const entry = createMockCacheEntry(odspResolvedUrlWithoutVersion, opType, "100_5"); | ||
const key = getKeyForCacheEntry(entry); | ||
assert.equal(key, "test-doc-id_ops_100_5"); | ||
}); | ||
it("creates a versioned op cache entry", () => { | ||
const entry = createMockCacheEntry(odspResolvedUrlWithVersion, opType, "100_5"); | ||
const key = getKeyForCacheEntry(entry); | ||
assert.equal(key, "test-doc-id_3.0_ops_100_5"); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.