Skip to content

fix: sync diagnostics row count#879

Merged
stevensJourney merged 5 commits intomainfrom
sync-diagnostics-table-count
Mar 9, 2026
Merged

fix: sync diagnostics row count#879
stevensJourney merged 5 commits intomainfrom
sync-diagnostics-table-count

Conversation

@stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented Mar 3, 2026

Overview

The Sync diagnostics app currently displays a row count per table in the sync diagnostics page.

image

This row count is currently obtained by counting the ops per table in ps_oplog.

SELECT row_type as name, count() as count, sum(length(data)) as size FROM ps_oplog GROUP BY row_type

TLDR: The above approach works if the rows only originate from a single bucket definition in the sync config.

More details:

ps_oplog stores ops with the schema:

CREATE TABLE ps_oplog(
  bucket INTEGER NOT NULL,
  op_id INTEGER NOT NULL,
  row_type TEXT,
  row_id TEXT,
  key TEXT,
  data TEXT,
  hash INTEGER NOT NULL) STRICT;

Where the ops are related to a bucket.

There will be multiple ps_oplog entries for a row if it is referenced from multiple sync bucket definitions. E.g.

bucket_definitions:
  # "global" sync rules will sync to all users. Note that 'global' is not a reserved word - buckets can be named anything
  global:
    data:
      # Sync all rows
      - SELECT * FROM organizations

  by_user:
    parameters:
      - SELECT request.user_id() as user_id
    data:
      - SELECT * FROM organizations where user_id = bucket.user_id
image

This causes the rowcount to be larger than the actual number of rows (which are deduplicated).

This updates the query logic to query the views directly for a row count.

Implementation

The Tables table now contains a Row Count column which should correlate to the number of synced rows present.
image

An additional Synced Count column is added to show the previous value as recommended here.
image

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: 58c1ce4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@powersync/diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@stevensJourney stevensJourney requested a review from rkistner March 3, 2026 11:59
Copy link
Contributor

@rkistner rkistner left a comment

Choose a reason for hiding this comment

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

Happy with the updates, just added some suggestions for wording

stevensJourney and others added 2 commits March 3, 2026 15:16
Co-authored-by: Ralf Kistner <ralf@journeyapps.com>
Co-authored-by: Ralf Kistner <ralf@journeyapps.com>
@stevensJourney stevensJourney marked this pull request as ready for review March 4, 2026 07:51
@stevensJourney stevensJourney merged commit 1f94d4b into main Mar 9, 2026
9 checks passed
@stevensJourney stevensJourney deleted the sync-diagnostics-table-count branch March 9, 2026 06:53
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.

2 participants