-
Notifications
You must be signed in to change notification settings - Fork 184
fix(artifacts): isolate in-memory composite keys #576
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
Changes from 2 commits
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 |
|---|---|---|
|
|
@@ -101,17 +101,19 @@ export class InMemoryArtifactService implements BaseArtifactService { | |
| userId, | ||
| sessionId, | ||
| }: ListArtifactKeysRequest): Promise<string[]> { | ||
| const sessionPrefix = `${appName}/${userId}/${sessionId}/`; | ||
| const usernamespacePrefix = `${appName}/${userId}/user/`; | ||
| const filenames: string[] = []; | ||
|
|
||
| for (const path in this.artifacts) { | ||
| if (path.startsWith(sessionPrefix)) { | ||
| const filename = path.replace(sessionPrefix, ''); | ||
| filenames.push(filename); | ||
| } else if (path.startsWith(usernamespacePrefix)) { | ||
| const filename = path.replace(usernamespacePrefix, ''); | ||
| filenames.push(filename); | ||
| const key = JSON.parse(path) as ArtifactStorageKey; | ||
| if ( | ||
| key[0] === 'session' && | ||
| key[1] === appName && | ||
| key[2] === userId && | ||
| key[3] === sessionId | ||
| ) { | ||
| filenames.push(key[4]); | ||
| } else if (key[0] === 'user' && key[1] === appName && key[2] === userId) { | ||
| filenames.push(key[3]); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -197,13 +199,13 @@ export class InMemoryArtifactService implements BaseArtifactService { | |
| } | ||
|
|
||
| /** | ||
| * Constructs the path to the artifact. | ||
| * Constructs the storage key for the artifact. | ||
| * | ||
| * @param appName The app name. | ||
| * @param userId The user ID. | ||
| * @param sessionId The session ID. | ||
| * @param filename The filename. | ||
| * @return The path to the artifact. | ||
| * @return The encoded storage key for the artifact. | ||
| */ | ||
| function artifactPath( | ||
| appName: string, | ||
|
|
@@ -212,12 +214,22 @@ function artifactPath( | |
| filename: string, | ||
| ): string { | ||
| if (fileHasUserNamespace(filename)) { | ||
| return `${appName}/${userId}/user/${filename}`; | ||
| return JSON.stringify(['user', appName, userId, filename]); | ||
| } | ||
|
|
||
| return `${appName}/${userId}/${sessionId}/${filename}`; | ||
| return JSON.stringify(['session', appName, userId, sessionId, filename]); | ||
|
Collaborator
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. Not a nit, but out of scope for this PR — worth a follow-up issue rather than a change here. The encoding on this line is right, but // core/src/artifacts/gcs_artifact_service.ts:283-285
const prefix = isUser
? `${appName}/${userId}/user/${cleanFilename}`
: `${appName}/${userId}/${sessionId}/${cleanFilename}`;
It is actually worse there than it was here. GCS strips the For contrast, I am not asking you to fix GCS in this PR; flagging it so #574 doesn't get closed as fully resolved when only one of the two implementations is fixed. |
||
| } | ||
|
|
||
| type ArtifactStorageKey = | ||
| | [ | ||
| 'session', | ||
| appName: string, | ||
| userId: string, | ||
| sessionId: string, | ||
| filename: string, | ||
| ] | ||
| | ['user', appName: string, userId: string, filename: string]; | ||
|
|
||
| /** | ||
| * Checks if the filename has a user namespace prefix. | ||
| * | ||
|
|
||
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.
Can we just encode/decode every part of the path (appName, userId, sessionId, filename) to not to have the delimiter (
/)?No need to create an array as a key. I think this is antipatern and better to keep keys as numbers or strings but not as objects.