Skip to content

feat: paginate runStats, fix verification script on Windows, and clean up react-hooks warning#123

Open
pritpatel2412 wants to merge 1 commit into
tinyfish-io:mainfrom
pritpatel2412:feat/runstats-pagination-and-verify-authz-fixes
Open

feat: paginate runStats, fix verification script on Windows, and clean up react-hooks warning#123
pritpatel2412 wants to merge 1 commit into
tinyfish-io:mainfrom
pritpatel2412:feat/runstats-pagination-and-verify-authz-fixes

Conversation

@pritpatel2412
Copy link
Copy Markdown

Description

This PR addresses three key areas to improve scalability, cross-platform local development, and clean up frontend compilation/linting:

  1. Query Pagination: Optimized the listByDataset and listByUser queries on the runStats table in Convex to use cursor-based pagination (.paginate()) instead of loading all historic records into memory (.collect()). This bounds memory usage and improves database performance.
  2. Cross-Platform Verification Script: Enhanced scripts/verify-authz.sh to check for python3 and fallback to python (which is standard on Windows hosts).
  3. Aligned Schema Payload in Tests: Corrected a legacy cadence payload argument inside the verification script to refreshCadence for datasets:create. This fixed a schema validation exception on Convex that was previously masking auth checks.
  4. React Linter Fix: Resolved a react-hooks/set-state-in-effect rule violation in use-row-change-detection.ts by wrapping setFlashingCells inside setTimeout(..., 0) to align with the repository's established code patterns.

Changes Made

  • Database Schema: Added compound indexes by_dataset_started_at (["datasetId", "startedAt"]) and by_user_started_at (["userId", "startedAt"]) in frontend/convex/schema.ts.
  • Database Queries: Changed listByDataset and listByUser to cursor-based paginated queries in frontend/convex/runStats.ts.
  • Authorization script: Updated scripts/verify-authz.sh with the Python binary checker and updated testing arguments.
  • Component table hook: Wrapped synchronous state setters in frontend/components/table/use-row-change-detection.ts in deferred callbacks.

Verification

  • Deployed updated schema successfully to local Convex backend.
  • Ran verification scripts successfully:
    bash scripts/verify-authz.sh

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces cursor-based pagination for run queries to improve scalability, adds supporting database indexes, defers cell flash updates in the table UI, and improves test script compatibility. The pagination work includes constants for page size bounds, updates to listByDataset and listByUser queries to use index-backed cursors instead of loading all records, and new composite indexes on the runStats table. A timing change in the row change detection hook defers the "flash on" effect via setTimeout(0). Test script improvements add Python interpreter detection and fix a field name in an authorization test payload.

Suggested reviewers

  • simantak-dabhade
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly summarizes the main changes: pagination for runStats, verification script fixes for Windows compatibility, and cleanup of a react-hooks linting warning.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the purpose and implementation details of all four areas of modification.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/convex/runStats.ts`:
- Around line 84-94: The current code only caps the upper bound for args.limit
but can pass zero, negative, fractional or NaN to paginate; update the
computation of limit (used before ctx.db.query(...).paginate and the similar
block around paginate at lines ~110-118) to normalize and clamp numItems to an
integer in [1, MAX_PAGE_SIZE] by coercing args.limit to a number, using
Math.floor (or equivalent) and Math.max(1, ...), then Math.min(...,
MAX_PAGE_SIZE) so paginate always receives a positive integer; reference the
variables/functions limit, args.limit, DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE and the
paginate call in runStats.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9de7d92b-f3e9-4212-a582-81a032afec81

📥 Commits

Reviewing files that changed from the base of the PR and between 5a2e7c3 and 4cdf47d.

📒 Files selected for processing (4)
  • frontend/components/table/use-row-change-detection.ts
  • frontend/convex/runStats.ts
  • frontend/convex/schema.ts
  • scripts/verify-authz.sh

Comment on lines +84 to +94
const limit = Math.min(args.limit ?? DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE);
const { page, isDone, continueCursor } = await ctx.db
.query("runStats")
.withIndex("by_dataset", (q) => q.eq("datasetId", args.datasetId))
.collect();
return runs.sort((a, b) => b.startedAt - a.startedAt);
.withIndex("by_dataset_started_at", (q) =>
q.eq("datasetId", args.datasetId),
)
.order("desc")
.paginate({
cursor: args.cursor ?? null,
numItems: limit,
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Clamp and normalize numItems before calling paginate.

Line 84 and Line 110 only cap the upper bound. Passing limit <= 0 (or a fractional value) can trigger runtime failures or undefined pagination behavior.

Suggested fix
-    const limit = Math.min(args.limit ?? DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE);
+    const requested = args.limit ?? DEFAULT_PAGE_SIZE;
+    const limit = Math.max(1, Math.min(Math.floor(requested), MAX_PAGE_SIZE));
@@
-    const limit = Math.min(args.limit ?? DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE);
+    const requested = args.limit ?? DEFAULT_PAGE_SIZE;
+    const limit = Math.max(1, Math.min(Math.floor(requested), MAX_PAGE_SIZE));

Also applies to: 110-118

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/convex/runStats.ts` around lines 84 - 94, The current code only caps
the upper bound for args.limit but can pass zero, negative, fractional or NaN to
paginate; update the computation of limit (used before
ctx.db.query(...).paginate and the similar block around paginate at lines
~110-118) to normalize and clamp numItems to an integer in [1, MAX_PAGE_SIZE] by
coercing args.limit to a number, using Math.floor (or equivalent) and
Math.max(1, ...), then Math.min(..., MAX_PAGE_SIZE) so paginate always receives
a positive integer; reference the variables/functions limit, args.limit,
DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE and the paginate call in runStats.

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