mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #753] [Feature]: wrap chat-folders POST /reorder-chats loop in db.transaction() (requires chatsStorage tx-param refactor) #360
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#360
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Romuromylus on GitHub (May 12, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/753
What problem does this solve?
POST /api/chat-folders/reorder-chats(inpackages/server/src/routes/chat-folders.routes.ts) loops overorderedChatIdsand runs two storage calls per chat without transaction boundaries:A partial failure mid-loop (DB write error, container restart, etc.) leaves chats in a mixed state — some moved into the new folder, others still in their old one — and the user has to manually re-sort.
This was the one remaining bullet from #748 that PR #749 deliberately did not address, because wrapping it requires a non-trivial storage refactor (see Proposed solution).
Proposed solution
Wrap the loop in
db.transaction(). This is more involved than the storage-side wraps in #749 because:chatsStorage.setFolderForChat(id, folderId)does branch-sibling propagation againstgroupId(so all branches of a chat move together). To run it inside a transaction,chatsStorageneeds to accept an optionaltxparameter for at leastupdateandsetFolderForChat, threading it through to the per-row UPDATEs.txplumbing is the actual scope of the work. Once in place, the route handler becomes:The same
tx-param convention can apply to any future storage call that needs to participate in a larger transaction, so the cost is amortised.Alternatives considered
chatsStorageentirely so we can run pure Drizzle insidedb.transaction). Possible but reproduces the branch-propagation logic in a second location — easy to drift.chatsStoragelikereorderInFolder(orderedIds, folderId)that does its own internal transaction. Cleaner separation of concerns but adds another bespoke method just for this route; the optional-txapproach is more generally useful.Additional context
Spun out from #748 / PR #749's "What was deliberately not changed" section. PR #749 wraps
create,reorder,reorderConnectionsin both folder storage modules atomically; this is the last remaining per-row loop in the folder code paths.Independent review of PR #749 flagged that
Closes #748would auto-close #748 on merge and silently drop this remaining work, hence carving it out into its own issue.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked: