refactor(rpc): deepen LinkService and thin links router - #698
refactor(rpc): deepen LinkService and thin links router#698sundaram2021 wants to merge 7 commits into
Conversation
|
@sundaram2021 is attempting to deploy a commit to the Databuddy OSS Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Shadow auto-approve: would not auto-approve because issues were found.
Re-trigger cubic
…cache on backfill and abandon lease on ambiguous create
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
Re-trigger cubic
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would require human review. Refactors the links router into a LinkService, but adds a new Redis Lua script with conditional cache-overwrite semantics (null/tombstone/invalid entries) not shown in the prior router path, so the 'no behavior change' claim is unverified and needs human sign-off.
Re-trigger cubic
Greptile SummaryThe PR moves link mutation, validation, persistence reconciliation, and Redis lease handling from the links router into LinkService, and adds a Redis backfill primitive plus focused service tests.
Confidence Score: 3/5The PR is not safe to merge until uncertain creates retain their lease and delayed create backfills cannot overwrite newer deletion tombstones. The changed cache lifecycle permits unresolved custom-slug creates to lose their coordination guard and permits an older generated-link backfill to restore a deleted link in Redis. Files Needing Attention: packages/rpc/src/services/link-service.ts and packages/redis/links-cache.ts Important Files Changed
Sequence DiagramsequenceDiagram
participant Router as Links Router
participant Service as LinkService
participant Redis as Redis Link Cache
participant DB as PostgreSQL
Router->>Service: create/update/delete
Service->>Redis: begin mutation lease
Service->>DB: persist mutation
alt confirmed success
Service->>Redis: publish link or tombstone
else definitive failure
Service->>Redis: abandon lease
else uncertain outcome
Service->>DB: reconcile
Service-->>Router: result or service unavailable
end
Reviews (1): Last reviewed commit: "refactor: update indentation" | Re-trigger Greptile |
…l from overwriting tombstones Keep pending lease for ambiguous inserts so late commits are not lost to negative caching or second writers; backfill now only replaces missing/null/corrupt entries, never pending or tombstone (prevents resurrecting deleted links).
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would require human review. Refactor continues, but the delta removes abandonLinkCacheMutations calls on uncertain persistence paths and retains a Lua script that overwrites null/invalid cache entries, so the 'no behavior change' claim is not substantiated and cache-consistency semantics need a human owner.
Re-trigger cubic
Summary
Deepens the Link module (candidate 01 from architecture review). Moves all distributed invariants — slug generation, deep-link validation, folder/targetDomain normalization, Redis lease lifecycle, PG error classification & reconciliation, and agent-context invalidation — from the shallow
links.tsrouter (1,042 LOC) into a single deepLinkServicemodule. Router becomes a thin adapter (303 LOC) that only does auth → service call → return.No behavior change — purely improvement / code optimization. Preserves existing error codes (
CONFLICT,SERVICE_UNAVAILABLE,BAD_REQUEST), retry semantics, fire-and-forget cache publish, andinvalidateAgentContexthandling.What changed
3 commits — one per file (code only):
feat(rpc): add LinkService deep module for link cache and persistence invariants—packages/rpc/src/services/link-service.ts(809 LOC)generateLinkSlug(nanoid 8),validateDeepLinkConfiguration,normalize*,validateFolderId,toCachedLink,hasPostgresSqlStateabandonLinkCacheMutations,finishLinkCacheMutation,backfillLinkCache,tombstoneLinkCacheMutations,beginLinkCacheMutations(sorted, token-checked) — directly calls@databuddy/redisLua scripts, no adapter interface (removed per ponytail review)create/update/delete/getLinkOrThrowwith full PG unique-violation vs definitive vs uncertain branching andisUniqueViolationForhandlingnormalizeTargetDomain/normalizeNullableTextfor reuse (deduplicated from router)refactor(rpc): thin links router to delegate to LinkService—packages/rpc/src/routers/links.ts(1,042 → 303 LOC, -739)buildLinkListConditions,buildLinkSearchCondition, pagination) andgetLinkOrThrowfor readscreate/update/deletenow:requireLinkAccess→new LinkService({ db: context.db })→svc.create/update/deletenormalize*,hasPostgresSqlState,isUniqueViolationFor, and all 5 cache helpers from routertest(rpc): add LinkService tests for helpers and cache lease invariants—packages/rpc/src/services/link-service.test.ts(315 LOC, 9 tests)normalizeNullableText/normalizeTargetDomain@databuddy/redisviamock.module+ fakedb(in-memoryMap, handles folder check / insert / reconciliation)BAD_REQUESTbefore DB), unknown folder, custom slug leaseacquired,busy→CONFLICT, Redis throw →SERVICE_UNAVAILABLE, generated slug23505retry, and backfillsetIfAbsentfire-and-forget pathImpact
links.ts+links-cache.ts+db/schema+redis)basket/linksconsumers can reuseLinkServiceinstead of copying ceremonydb+ mockedredis(9 new tests); router no longer needs DB for lease logiccreate(input) → Link | throw/update(link, patch)/delete(link)— implementation absorbs 5 helpers + 3 error branchesNet:
-130lines removed after ponytail trim (deletedLinkCachePort,createProdLinkCache/createInMemoryLinkCache,generate*DI, duplicated helpers,setTimeoutshim). No new dependencies.Tests ran
bun test --isolate packages/rpc/src/services/link-service.test.ts— 9 pass, 0 fail (26 expects)bun test --isolate packages/rpc/src/routers/links.test.ts— pass (validatescreateLinkSchema/updateLinkSchemastill correct)bun test --isolate packages/rpc/src/routers/links.test.ts packages/redis/links-cache.test.ts packages/rpc/src/services/link-service.test.ts packages/rpc/src/services/insight-schedule.test.ts— 34 pass, 0 failbun test --isolate packages/rpc/src/services/link-service.test.ts packages/rpc/src/routers/links.test.ts packages/rpc/src/routers/link-folders.test.ts packages/rpc/src/utils/billing.test.ts packages/redis/links-cache.test.ts— 43 pass, 0 failbun tsc --noEmit --project packages/rpc/tsconfig.json— passbunx ultracite check— pass (no fixes)bun run lint:policies— 14 passNo functional change — existing
links.test.ts/links-cache.test.tsstill pass; error codes and retry semantics preserved.Summary by cubic
Moves all link mutation logic (slug generation, cache lease handling, PG error classification, folder/domain normalization) from the
linksrouter into a newLinkService, leaving the router to handle auth and return responses. Error codes and retry semantics are preserved, with behavior changes listed below.Behavior changes
setCachedLinkIfAbsentOrNotFoundRedis script lets backfill replace missing, null, or malformed cache entries, but never a pending mutation or tombstone.createdByis resolved after deep-link and folder validation.Written for commit f96f300. Summary will update on new commits.