Skip to content

chore: track pending update count #1494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Horusiath
Copy link
Collaborator

@Horusiath Horusiath commented Jun 30, 2025

Summary by Sourcery

Track pending update count per collaboration session to improve synchronization and reduce redundant update messages, and apply minor protocol fixes.

Enhancements:

  • Add a pending_updates atomic counter and change_pending_count method to CachedCollab
  • Increment and decrement the pending counter on local update dispatch and acknowledgement
  • Optimize update dispatch by sending an empty update when the local state and pending count indicate full sync
  • Use the actual last_message_id in manifest responses instead of the default
  • Refactor the WsInput handler to clone the manager store in the correct scope

@Horusiath Horusiath requested a review from appflowy June 30, 2025 05:10
Copy link

sourcery-ai bot commented Jun 30, 2025

Reviewer's Guide

Adds an atomic pending-update counter to CachedCollab, hooks increment/decrement calls into the local-update send/ack pipeline, optimizes redundant diff messages when state is already in sync, and fixes minor defaults and code cleanup in the WS2 workspace actor.

Sequence diagram for local update send/ack and pending update count

sequenceDiagram
    participant Client
    participant WorkspaceControllerActor
    participant CachedCollab

    Client->>WorkspaceControllerActor: Send local update
    WorkspaceControllerActor->>CachedCollab: change_pending_count(object_id, +1)
    WorkspaceControllerActor->>WorkspaceControllerActor: trigger send
    WorkspaceControllerActor->>Client: (possibly error)
    WorkspaceControllerActor->>CachedCollab: change_pending_count(object_id, -1) (on ack)
Loading

Class diagram for CachedCollab and pending update tracking

classDiagram
    class CachedCollab {
        - WeakCollabRef collab_ref
        - CollabType collab_type
        - AtomicU64 pending_updates
        + upgrade() Option<CollabRef>
        + pending_updates() u64
    }

    class WorkspaceControllerActor {
        + change_pending_count(object_id: &ObjectId, by: i64) Option<u64>
        + remove_collab(object_id: &ObjectId)
        + handle_send(msg: ClientMessage, source: ActionSource) async
    }

    WorkspaceControllerActor --> CachedCollab : manages
Loading

File-Level Changes

Change Details Files
Introduce atomic pending‐update counter in CachedCollab
  • Add AtomicU64 pending_updates field and initialize to 0
  • Provide pending_updates() getter
  • Implement change_pending_count method with fetch_add/ fetch_sub
libs/client-api/src/v2/actor.rs
Integrate pending‐update adjustments into local‐update send logic
  • Capture object_id in handle_send to call change_pending_count
  • Decrement pending count after successful send for local-origin updates
  • Increment pending count when queuing a new local update
libs/client-api/src/v2/actor.rs
Skip sending full diffs when already in sync
  • Compare local state vector & pending_updates to remote state_vector
  • Log a sync message and send EMPTY_V1 update when no diff needed
libs/client-api/src/v2/actor.rs
Fix defaults and cleanup in WS2 workspace actor
  • Use state.rid instead of Rid::default() for last_message_id
  • Move manager.clone() into conditional branch to simplify code
services/appflowy-collaborate/src/ws2/actors/workspace.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Horusiath - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant