fix: prevent duplicate pending operations in mod queue - #359
Merged
Conversation
Adds partial unique indexes on `pending_operations` table to enforce one pending operation per (mod/addon, action) pair. This prevents duplicate queue entries when multiple users or requests attempt to queue the same operation concurrently. Changes: - Migration 019: Add unique indexes for mod and addon operations - insert_pending_op: Return friendly error message for duplicates - has_pending_url_op: Add dedup check for URL-based installs - URL install handler: Check for duplicates before download and handle constraint violations gracefully with user-facing messages Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Applies the same SQLITE_CONSTRAINT_UNIQUE handling pattern used in URL installs to mod and addon removal queue operations. On the rare race condition where has_pending_op() passes but the unique index catches a duplicate, users now see a friendly "already queued" flash message instead of a raw 500 error. Additionally, add missing queueing support to remove_addon handler (previously it would always perform immediate removal even when the server was running and queue mode was enabled). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Changes
Migration 019: Creates partial unique indexes on
pending_operations:idx_pending_ops_mod_actionon(forge_mod_id, action)for mod operationsidx_pending_ops_addon_actionon(forge_addon_id, action)for addon operationsDatabase layer (
src/db/users.rs):insert_pending_op: Returns friendly error message for UNIQUE constraint violationshas_pending_url_op: New helper to check for duplicate URL-based operationsWeb handler (
src/web/handlers/mods.rs):Test plan
just checkjust clippyRoot Cause
The
pending_operationstable had no unique constraint on(forge_mod_id, action)or(forge_addon_id, action), allowing duplicate pending operations to be queued.Implemented with the help of Claude Code