-
Notifications
You must be signed in to change notification settings - Fork 246
chore(user-data): remove redundant withStats methods #7134
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 1 commit
ef94ff8
3f8405a
7f07ddd
e09d426
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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import type { Stats } from '@mongodb-js/compass-user-data'; | ||
| import { FileUserData } from '@mongodb-js/compass-user-data'; | ||
| import { PipelineSchema } from './pipeline-storage-schema'; | ||
| import type { SavedPipeline } from './pipeline-storage-schema'; | ||
|
|
@@ -13,21 +12,10 @@ export class CompassPipelineStorage implements PipelineStorage { | |
| }); | ||
| } | ||
|
|
||
| private mergeStats(pipeline: SavedPipeline, stats: Stats): SavedPipeline { | ||
|
Collaborator
Author
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. That was the only case where we use it, and even then we always write our own number on create / update |
||
| return { | ||
| ...pipeline, | ||
| lastModified: new Date(stats.ctimeMs), | ||
| }; | ||
| } | ||
|
|
||
| async loadAll(): Promise<SavedPipeline[]> { | ||
| try { | ||
| const { data } = await this.userData.readAllWithStats({ | ||
| ignoreErrors: false, | ||
| }); | ||
| return data.map(([item, stats]) => { | ||
| return this.mergeStats(item, stats); | ||
| }); | ||
| const { data } = await this.userData.readAll(); | ||
| return data; | ||
| } catch { | ||
| return []; | ||
| } | ||
|
|
@@ -41,16 +29,11 @@ export class CompassPipelineStorage implements PipelineStorage { | |
| } | ||
|
|
||
| private async loadOne(id: string): Promise<SavedPipeline> { | ||
| const [item, stats] = await this.userData.readOneWithStats(id); | ||
| return this.mergeStats(item, stats); | ||
| return await this.userData.readOne(id); | ||
| } | ||
|
|
||
| async createOrUpdate(id: string, attributes: SavedPipeline) { | ||
| const pipelineExists = Boolean( | ||
| await this.userData.readOne(id, { | ||
| ignoreErrors: true, | ||
| }) | ||
| ); | ||
| const pipelineExists = Boolean(await this.userData.readOne(id)); | ||
| return await (pipelineExists | ||
| ? this.updateAttributes(id, attributes) | ||
| : this.create(attributes)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,8 +62,8 @@ export const PipelineSchema = z.preprocess( | |
| pipelineText: z.string(), | ||
| lastModified: z | ||
| .number() | ||
| .transform((x) => new Date(x)) | ||
| .optional(), | ||
| .default(0) | ||
|
Collaborator
Author
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. In the rarest case ever if someone still somehow doesn't have this value stored, we fallback to zero, the logic for writing this value to UserData was here for such a long time, I don't think this will ever be used |
||
| .transform((x) => new Date(x)), | ||
| }) | ||
| ); | ||
|
|
||
|
|
||
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.
This shape with returned errors is also not used anywhere really, we always pick up data, but it's a bigger change and this part of the interface doesn't depend on fs, so not touching it