Skip to content

♻️ refactor(recent): rewrite queryRecent in Drizzle, exclude web-tool scrapes#14239

Merged
arvinxx merged 2 commits into
canaryfrom
refactor/recent-drizzle
Apr 27, 2026
Merged

♻️ refactor(recent): rewrite queryRecent in Drizzle, exclude web-tool scrapes#14239
arvinxx merged 2 commits into
canaryfrom
refactor/recent-drizzle

Conversation

@arvinxx

@arvinxx arvinxx commented Apr 27, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • ♻️ refactor

🔀 Description of Change

Rewrites RecentModel.queryRecent and tightens its filters.

  • Replace the raw SQL UNION with Drizzle's typed unionAll (topicArm / documentArm / taskArm), so the query is type-checked end-to-end and the result mapping no longer goes through db.execute().rows.
  • Hoist the filter lists into named module-level constants (SYSTEM_TOPIC_TRIGGERS, TOOL_DOCUMENT_SOURCE_TYPES, TASK_FINAL_STATUSES) to make the intent self-documenting at the call sites.
  • Exclude documents whose sourceType is in ('file', 'web'). Previously only 'file' was excluded, so web-browsing tool scrapes (sourceType = 'web') were leaking into the Recent list. Only user-authored pages ('api') and legacy 'topic' rows now surface.
  • Adds a RecentModel test suite covering topic/document/task arms, the new exclusion, system-trigger filtering, and ordering/limit.

No schema changes. Output shape unchanged.

🧪 How to Test

  • Added/updated tests
cd packages/database && bunx vitest run --silent='passed-only' src/models/__tests__/recent.test.ts

Manual check: in a workspace with web-tool browsing history, the Recent list should no longer include scraped web pages — only your own pages, topics, and active tasks.

… scrapes

- Replace raw SQL UNION with Drizzle's typed unionAll (topicArm/documentArm/taskArm)
- Hoist filter lists into named constants (SYSTEM_TOPIC_TRIGGERS,
  TOOL_DOCUMENT_SOURCE_TYPES, TASK_FINAL_STATUSES) for readability
- Recent now excludes documents whose sourceType is in ('file', 'web') so
  web-browsing tool scrapes stop leaking in alongside file uploads
- Add RecentModel test coverage
@vercel

vercel Bot commented Apr 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Apr 27, 2026 4:28pm

Request Review

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 27, 2026

@sourcery-ai sourcery-ai Bot left a comment

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.

Sorry @arvinxx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.10%. Comparing base (a4235d3) to head (2ea67dd).
⚠️ Report is 13 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #14239      +/-   ##
==========================================
+ Coverage   68.09%   68.10%   +0.01%     
==========================================
  Files        2267     2268       +1     
  Lines      194367   194459      +92     
  Branches    19563    24297    +4734     
==========================================
+ Hits       132353   132443      +90     
- Misses      61884    61886       +2     
  Partials      130      130              
Flag Coverage Δ
app 61.60% <ø> (-0.01%) ⬇️
database 92.09% <100.00%> (+0.05%) ⬆️
packages/agent-runtime 79.93% <ø> (ø)
packages/context-engine 83.25% <ø> (ø)
packages/conversation-flow 92.40% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 74.74% <ø> (ø)
packages/model-bank 99.89% <ø> (ø)
packages/model-runtime 84.29% <ø> (ø)
packages/prompts 68.17% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 88.36% <ø> (ø)
packages/web-crawler 88.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 67.18% <ø> (ø)
Services 53.36% <ø> (ø)
Server 68.44% <ø> (-0.01%) ⬇️
Libs 53.30% <ø> (ø)
Utils 80.04% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…Array

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@arvinxx arvinxx merged commit 2a37b77 into canary Apr 27, 2026
35 checks passed
@arvinxx arvinxx deleted the refactor/recent-drizzle branch April 27, 2026 17:24
sxueck pushed a commit to sxueck/lobehub that referenced this pull request Apr 28, 2026
… scrapes (lobehub#14239)

* ♻️ refactor(recent): rewrite queryRecent in Drizzle, exclude web-tool scrapes

- Replace raw SQL UNION with Drizzle's typed unionAll (topicArm/documentArm/taskArm)
- Hoist filter lists into named constants (SYSTEM_TOPIC_TRIGGERS,
  TOOL_DOCUMENT_SOURCE_TYPES, TASK_FINAL_STATUSES) for readability
- Recent now excludes documents whose sourceType is in ('file', 'web') so
  web-browsing tool scrapes stop leaking in alongside file uploads
- Add RecentModel test coverage

* 🐛 fix(recent): widen TOOL_DOCUMENT_SOURCE_TYPES to const tuple for inArray

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mutoe pushed a commit to mutoe/lobehub that referenced this pull request May 1, 2026
… scrapes (lobehub#14239)

* ♻️ refactor(recent): rewrite queryRecent in Drizzle, exclude web-tool scrapes

- Replace raw SQL UNION with Drizzle's typed unionAll (topicArm/documentArm/taskArm)
- Hoist filter lists into named constants (SYSTEM_TOPIC_TRIGGERS,
  TOOL_DOCUMENT_SOURCE_TYPES, TASK_FINAL_STATUSES) for readability
- Recent now excludes documents whose sourceType is in ('file', 'web') so
  web-browsing tool scrapes stop leaking in alongside file uploads
- Add RecentModel test coverage

* 🐛 fix(recent): widen TOOL_DOCUMENT_SOURCE_TYPES to const tuple for inArray

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant