Skip to content

perf(home): denormalize recent workflows into WorkspaceRecentWorkflow#1003

Open
anish-work wants to merge 3 commits into
feat/home-pagefrom
perf/home-recent-workflows
Open

perf(home): denormalize recent workflows into WorkspaceRecentWorkflow#1003
anish-work wants to merge 3 commits into
feat/home-pagefrom
perf/home-recent-workflows

Conversation

@anish-work

Copy link
Copy Markdown
Contributor

The home page derived "recent workflows" by scanning a workspace's entire SavedRun history with DISTINCT ON, which is O(total runs) and measured ~2.4s on the heaviest workspace (1.78M runs collapsing to 1 distinct workflow).

Add a denormalized WorkspaceRecentWorkflow table keyed by (workspace, uid, published_run) storing last_saved_run + last_used_at, upserted on run creation in create_new_run (covers UI + API paths). The home read now hits an index for ~4 rows instead of disk-sorting millions, and renders the card via a select_related PK join (no SavedRun index needed).

Includes a one-time DISTINCT ON backfill migration for existing history.

Q/A checklist

  • I have tested my UI changes on mobile and they look acceptable
  • I have tested changes to the workflows in both the API and the UI
  • I have done a code review of my changes and looked at each line of the diff + the references of each function I have changed
  • My changes have not increased the import time of the server
How to check import time?

time python -c 'import server'

You can visualize this using tuna:

python3 -X importtime -c 'import server' 2> out.log && tuna out.log

To measure import time for a specific library:

$ time python -c 'import pandas'

________________________________________________________
Executed in    1.15 secs    fish           external
   usr time    2.22 secs   86.00 micros    2.22 secs
   sys time    0.72 secs  613.00 micros    0.72 secs

To reduce import times, import libraries that take a long time inside the functions that use them instead of at the top of the file:

def my_function():
    import pandas as pd
    ...

Legal Boilerplate

Look, I get it. The entity doing business as “Gooey.AI” and/or “Dara.network” was incorporated in the State of Delaware in 2020 as Dara Network Inc. and is gonna need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Dara Network Inc can use, modify, copy, and redistribute my contributions, under its choice of terms.

@anish-work anish-work requested a review from devxpy June 11, 2026 08:21
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 47ef42f7-4506-4f11-882e-ea0761687492

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@anish-work anish-work force-pushed the perf/home-recent-workflows branch from b19f24a to 4a51d7c Compare June 11, 2026 08:23
The home page derived "recent workflows" by scanning a workspace's entire
SavedRun history with DISTINCT ON, which is O(total runs) and measured ~2.4s
on the heaviest workspace (1.78M runs collapsing to 1 distinct workflow).

Add a denormalized WorkspaceRecentWorkflow table keyed by
(workspace, uid, published_run) storing last_saved_run + last_used_at,
upserted on run creation in create_new_run (covers UI + API paths). The home
read now hits an index for ~4 rows instead of disk-sorting millions, and
renders the card via a select_related PK join (no SavedRun index needed).

Includes a one-time DISTINCT ON backfill migration for existing history.

Co-authored-by: Cursor <cursoragent@cursor.com>
@anish-work anish-work force-pushed the perf/home-recent-workflows branch from 4a51d7c to cd03051 Compare June 11, 2026 08:26
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