Skip to content

Fix when Moving Event, Note/Event Becomes Duplicated#1055

Merged
yujonglee merged 2 commits intofastrepl:mainfrom
plyght:plyght/fix-moving-dupe
Jul 8, 2025
Merged

Fix when Moving Event, Note/Event Becomes Duplicated#1055
yujonglee merged 2 commits intofastrepl:mainfrom
plyght:plyght/fix-moving-dupe

Conversation

@plyght
Copy link
Contributor

@plyght plyght commented Jul 2, 2025

fixes #961

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 2, 2025

📝 Walkthrough

Walkthrough

A new asynchronous method for updating events was added to the user database implementation. The Apple Calendar synchronization logic was enhanced to detect and process rescheduled events by updating existing database records when matching events are found with changed tracking IDs. Supporting structures and methods were updated to facilitate this flow.

Changes

File(s) Change Summary
crates/db-user/src/events_ops.rs Added update_event async method to UserDatabase for updating event records by ID using named SQL parameters.
plugins/apple-calendar/src/sync.rs Enhanced sync logic to detect rescheduled events, update events in the database, track updates in to_update, and execute updates. Added helper for reschedule detection, updated test coverage, and adjusted insertion logic.

Sequence Diagram(s)

sequenceDiagram
    participant SystemCalendar
    participant SyncLogic
    participant UserDatabase

    SystemCalendar->>SyncLogic: Provide all events
    SyncLogic->>UserDatabase: Fetch all DB events
    loop For each DB event
        SyncLogic->>SystemCalendar: Check for event with matching tracking_id
        alt Match found
            SyncLogic->>UserDatabase: Schedule update with latest event details
        else No exact match
            SyncLogic->>SystemCalendar: Search for rescheduled event (name match, start date within 30 days, different tracking_id)
            alt Rescheduled event found
                SyncLogic->>UserDatabase: Schedule update with new tracking_id and details
            else Not found
                SyncLogic->>UserDatabase: Mark event for deletion
            end
        end
    end
    SyncLogic->>UserDatabase: Insert new events (skip already updated/handled)
    SyncLogic->>UserDatabase: Execute updates via update_event for each to_update
Loading

Assessment against linked issues

Objective Addressed Explanation
Detect and handle event rescheduling to avoid duplicate events and preserve user notes (#961)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Clippy (1.86.0)
Updating git repository `https://github.com/RustAudio/cpal`

error: failed to load source for dependency cpal

Caused by:
Unable to update https://github.com/RustAudio/cpal?rev=51c3b43#51c3b43c

Caused by:
failed to create directory /usr/local/git/db/cpal-476cd1dd23dbc279

Caused by:
Permission denied (os error 13)


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 979ce3a and 4b0197e.

📒 Files selected for processing (2)
  • crates/db-user/src/events_ops.rs (1 hunks)
  • plugins/apple-calendar/src/sync.rs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/db-user/src/events_ops.rs
  • plugins/apple-calendar/src/sync.rs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: ci (macos, macos-latest)
  • GitHub Check: ci
  • GitHub Check: ci (windows, windows-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebcfadf and 979ce3a.

📒 Files selected for processing (2)
  • crates/db-user/src/events_ops.rs (1 hunks)
  • plugins/apple-calendar/src/sync.rs (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{js,ts,tsx,rs}`: 1. No error handling. 2. No unused imports, variables, or functions. 3. For comments, keep it minimal. It should be about "Why", not "What".

**/*.{js,ts,tsx,rs}: 1. No error handling.
2. No unused imports, variables, or functions.
3. For comments, keep it minimal. It should be about "Why", not "What".

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • crates/db-user/src/events_ops.rs
  • plugins/apple-calendar/src/sync.rs
🧬 Code Graph Analysis (1)
crates/db-user/src/events_ops.rs (4)
plugins/db/js/bindings.gen.ts (1)
  • Event (156-156)
crates/db-core/src/lib.rs (1)
  • conn (17-22)
crates/db-user/src/sessions_types.rs (1)
  • from_row (26-63)
crates/db-user/src/extensions_types.rs (1)
  • from_row (43-57)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: ci (windows, windows-latest)
  • GitHub Check: ci (macos, macos-latest)
  • GitHub Check: ci
🔇 Additional comments (3)
plugins/apple-calendar/src/sync.rs (3)

116-122: LGTM!

Efficient collection of system events using references to avoid unnecessary cloning.


139-183: Well-implemented event update logic.

The code correctly handles both exact tracking ID matches and potential reschedules, while preserving important fields like the database ID and google_event_url. This ensures user data (sessions/notes) remains associated with the event.


201-233: Correct deduplication logic and consistent error handling.

The code properly avoids duplicating events that have been handled as updates or already exist in the database. The error handling follows the existing pattern of logging errors without propagation.

Also applies to: 412-417

@yujonglee yujonglee merged commit 0604441 into fastrepl:main Jul 8, 2025
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jul 23, 2025
This was referenced Aug 14, 2025
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.

When moving an event to some other time, it shows the previous note and event separately.

2 participants