Skip to content

run lazy aggregate reads on a stale snapshot - #239

Open
reeceyang wants to merge 1 commit into
reece/internal-commitTS-convex-buildfrom
reece/run-lazy-aggregate-reads-on-a-stale-snapshot
Open

run lazy aggregate reads on a stale snapshot#239
reeceyang wants to merge 1 commit into
reece/internal-commitTS-convex-buildfrom
reece/run-lazy-aggregate-reads-on-a-stale-snapshot

Conversation

@reeceyang

@reeceyang reeceyang commented Jul 27, 2026

Copy link
Copy Markdown

Adds a lazy option to read methods, which will run the query with useStaleSnapshot in mutations.

@reeceyang
reeceyang force-pushed the reece/run-lazy-aggregate-reads-on-a-stale-snapshot branch 2 times, most recently from 58ad58a to 3fb7d7f Compare July 27, 2026 20:13
@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@convex-dev/aggregate@239

commit: 88bdb4a

@reeceyang
reeceyang force-pushed the reece/run-lazy-aggregate-reads-on-a-stale-snapshot branch from 3fb7d7f to 6af4ee0 Compare July 27, 2026 20:15
@reeceyang
reeceyang changed the base branch from main to reece/internal-commitTS-convex-build July 27, 2026 20:15
@reeceyang
reeceyang force-pushed the reece/run-lazy-aggregate-reads-on-a-stale-snapshot branch from 6af4ee0 to af978ff Compare July 27, 2026 20:30
@reeceyang

Copy link
Copy Markdown
Author

For read operations, I wonder if stale would make more sense as the option name? Write operations would still be lazy. It could be nice if the options are named the same, though, for consistency.

@reeceyang
reeceyang requested a review from ianmacartney July 27, 2026 20:35
@reeceyang
reeceyang force-pushed the reece/run-lazy-aggregate-reads-on-a-stale-snapshot branch from af978ff to 88bdb4a Compare July 27, 2026 23:56
@reeceyang
reeceyang force-pushed the reece/run-lazy-aggregate-reads-on-a-stale-snapshot branch from 88bdb4a to b6200fb Compare July 29, 2026 18:29
@reeceyang
reeceyang marked this pull request as ready for review July 29, 2026 19:19

@ianmacartney ianmacartney left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

overall lgtm. However, I do agree that "stale" makes more sense on the read path. I feel like I led you astray by pointing out the awkwardness on the write path. What do you think about naming:
- stale:true on queries where it's using stale snapshot & ignoring pending ops
- async:true on mutations where it's enqueueing the operation
?

Comment thread src/client/index.ts Outdated
});
}
// `lazy` is ignored in actions and queries, where all reads may be stale.
// We will throw an error in queries if there are pending operations that have not been applied.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: try to avoid comments that describe actions at a distance that may not stay up to date

Comment thread src/client/index.ts Outdated
useStaleSnapshot: true,
});
}
// `lazy` is ignored in actions and queries, where all reads may be stale.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this isn't quite true: all reads aren't stale in queries, and from actions they're sort of "stale", in that they don't conflict, but there isn't something non-stale to compare them to there.. so maybe just clarify that from actions, it won't conflict but from queries it will?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yeah that makes sense - I think I was trying to express that if there are still pending operations, the aggregate isn't fully consistent yet, so lazy reads in actions and queries do not see the effects the pending operations.

@reeceyang

Copy link
Copy Markdown
Author

I like stale and async!

@reeceyang
reeceyang force-pushed the reece/run-lazy-aggregate-reads-on-a-stale-snapshot branch from b6200fb to 62d070c Compare July 30, 2026 20:39
@reeceyang
reeceyang force-pushed the reece/run-lazy-aggregate-reads-on-a-stale-snapshot branch 2 times, most recently from 0dd012a to b574acb Compare July 30, 2026 21:06
@reeceyang
reeceyang force-pushed the reece/run-lazy-aggregate-reads-on-a-stale-snapshot branch from b574acb to 6da7560 Compare July 31, 2026 22:50
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