-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ef94ff8
chore(user-data): remove redundant withStats methods
gribnoysup 3f8405a
fix(user-data): remove nonexistent exports
gribnoysup 7f07ddd
fix(my-queries-storage): adjust types to match the method behavior
gribnoysup e09d426
fix(saved-aggregations-queries): adjust test fixture
gribnoysup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| export type { Stats, ReadAllResult, ReadAllWithStatsResult } from './user-data'; | ||
| export type { ReadAllResult } from './user-data'; | ||
| export { IUserData, FileUserData } from './user-data'; | ||
| export { z } from 'zod'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,22 +29,20 @@ 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, | ||
| }) | ||
| ); | ||
| async createOrUpdate( | ||
| id: string, | ||
| attributes: Omit<SavedPipeline, 'lastModified'> | ||
| ) { | ||
| const pipelineExists = Boolean(await this.userData.readOne(id)); | ||
| return await (pipelineExists | ||
| ? this.updateAttributes(id, attributes) | ||
| : this.create(attributes)); | ||
| } | ||
|
|
||
| private async create(data: SavedPipeline) { | ||
| private async create(data: Omit<SavedPipeline, 'lastModified'>) { | ||
| await this.userData.write(data.id, { | ||
| ...data, | ||
| lastModified: Date.now(), | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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