Skip to content

Conversation

@dewabisma
Copy link
Contributor

@dewabisma dewabisma commented Dec 22, 2025

Summary

Now user need only to input one data. More check to ensure valid owner of reply tweet.

Changes

  • make target_id optional in table column
  • check reply is actually owned by raider
  • update related tests

- make target_id optional in table column
- check reply is actually owned by raider
- update related tests
@dewabisma dewabisma requested review from illuzen and n13 December 22, 2025 09:39
Copy link
Contributor

@n13 n13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: Feat - Simplify Raid Submission

The implementation looks solid and adheres to the project's structure. The use of existing repositories and helper functions like parse_x_status_url keeps the code DRY.

I have a few suggestions to improve performance and robustness, specifically within handle_create_raid_submission.

1. Optimization: Check "Active Raid" First

In src/handlers/raid_quest.rs, the handler currently parses the target link and queries the relevant_tweets table before checking if there is an active raid.

If no raid is active, we should fail immediately to avoid unnecessary parsing and database lookups.

Recommendation: Move the active raid check to the top of the handler.

// Move this check to the start of handle_create_raid_submission
let Some(current_active_raid) = state.db.raid_quests.find_active().await? else {
    return Err(AppError::Database(DbError::RecordNotFound(format!(
        "No active raid is found"
    ))));
};

2. Check User Association Early

Similar to the active raid check, verifying the user's X association can be done earlier. If the user isn't linked, we don't need to parse URLs or look up the target tweet.

Proposed Order of Operations:

  1. Check Active Raid (System availability)
  2. Check X Association (User eligibility)
  3. Parse & Validate Links (Input validation)
  4. Check Target Tweet (Business logic)
  5. Create Submission

3. Idempotency Handling

The creation of a raid submission uses the tweet ID as the primary key. If a user submits the same reply twice (e.g., due to a network retry), this will likely throw a generic database error (Unique Constraint Violation).

Suggestion: Consider handling the unique violation explicitly. Returning a 409 Conflict would be more descriptive for the frontend than a generic 500 or database error.

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.

3 participants