Skip to content

BB-670: Replace Promise anti-patterns with async/await in utils and entity routes#1258

Open
garvthakre wants to merge 1 commit intometabrainz:masterfrom
garvthakre:BB-670-remove-promise-antipatterns
Open

BB-670: Replace Promise anti-patterns with async/await in utils and entity routes#1258
garvthakre wants to merge 1 commit intometabrainz:masterfrom
garvthakre:BB-670-remove-promise-antipatterns

Conversation

@garvthakre
Copy link
Copy Markdown
Contributor

Problem

Several functions in the server-side codebase use old-style .then()/.catch() promise chains and unnecessary new Promise(resolve => resolve(value)) anti-patterns instead of async/await syntax, making the code harder to read and maintain.

Part of BB-670: Rewrite promises to async/await syntax.

Solution

1.Converted incrementEditorEditCountById() in utils.ts from a .then().catch() chain to async/await with try/catch .

2.Removed three new Promise(resolve => resolve(x)) anti-patterns in entity.tsx:

3.setParentRevisions(): early return null directly instead of wrapping in a Promise

4.fetchOrCreateMainEntity(): return entity directly instead of wrapping in a Promise .

5.Rewrote displayEntity() from a nested .then() chain to a flat async/await + try/catch structure

Areas of Impact

=>src/server/helpers/utils.ts — incrementEditorEditCountById helper

=>src/server/routes/entity/entity.tsx— displayEntity, setParentRevisions, fetchOrCreateMainEntity functions

@garvthakre
Copy link
Copy Markdown
Contributor Author

@MonkeyDo ,i opened this PR as a part of working on BB-670 , can u give a review , whenever u got the time.

@faizanakhtar123
Copy link
Copy Markdown
Contributor

faizanakhtar123 commented Mar 9, 2026

Hi @garvthakre Thank you for opening this PR.... Please fill in the "AI usage" section in the PR template, it is there for a reason...
For better understanding - metabrainz/listenbrainz-server#3610

@garvthakre
Copy link
Copy Markdown
Contributor Author

Thanks for the note @faizanakhtar123 , but currently in bookbrainz's PR template doesn't currently have an AI usage field similar listenbrainz , i'll mention it to @MonkeyDo in case it's worth adding.

@faizanakhtar123
Copy link
Copy Markdown
Contributor

@garvthakre The AI usage guideline is actually a standard policy for all MetaBrainz PRs across the entire ecosystem Adding it to the BB template will simply make it easier for contributors to follow that global policy..

@garvthakre
Copy link
Copy Markdown
Contributor Author

Added an AI usage note to the description.

@garvthakre garvthakre changed the title Replace Promise anti-patterns with async/await in utils and entity routes BB-670: Replace Promise anti-patterns with async/await in utils and entity routes Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants