BB-670: Replace Promise anti-patterns with async/await in utils and entity routes#1258
BB-670: Replace Promise anti-patterns with async/await in utils and entity routes#1258garvthakre wants to merge 1 commit intometabrainz:masterfrom
Conversation
|
@MonkeyDo ,i opened this PR as a part of working on BB-670 , can u give a review , whenever u got the time. |
|
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... |
|
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. |
|
@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.. |
|
Added an AI usage note to the description. |
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