Skip to content

fix: test concurrent cache-miss#4340

Merged
ulemons merged 1 commit into
mainfrom
fix/debuging-query-members
Jul 15, 2026
Merged

fix: test concurrent cache-miss#4340
ulemons merged 1 commit into
mainfrom
fix/debuging-query-members

Conversation

@ulemons

@ulemons ulemons commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

improve lock for redis

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Performance improvement
  • Chore / dependency update
  • Documentation

Copilot AI review requested due to automatic review settings July 14, 2026 12:37
@ulemons ulemons self-assigned this Jul 14, 2026
@ulemons ulemons added the Bug Created by Linear-GitHub Sync label Jul 14, 2026
@ulemons ulemons force-pushed the fix/debuging-query-members branch from ff626b1 to 7c5a0bb Compare July 14, 2026 12:38

Copilot AI 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.

Pull request overview

This PR introduces a Redis-based “single-flight” helper and integrates it into the members advanced query cache-miss/refresh paths to prevent concurrent requests from stampeding the database on cold keys.

Changes:

  • Added withSingleFlight helper in @crowd/redis to coordinate concurrent callers behind a lock while polling cache.
  • Updated queryMembersAdvanced to single-flight cache misses and align background refresh locking with the same primitive.
  • Added a shared cap constant to prevent the activityCount top‑N optimization from silently truncating oversized pages.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
services/libs/redis/src/singleFlight.ts New single-flight helper built on existing Redis mutex primitives.
services/libs/redis/src/index.ts Exports the new single-flight helper from the redis lib barrel.
services/libs/data-access-layer/src/members/queryCache.ts Removes the previous refresh-lock helpers from MemberQueryCache.
services/libs/data-access-layer/src/members/queryBuilder.ts Adds a shared top‑N cap constant and guards optimized path against truncation.
services/libs/data-access-layer/src/members/base.ts Uses single-flight on members advanced cache misses and switches background refresh locking to acquireLock/releaseLock.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/libs/data-access-layer/src/members/base.ts
Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/data-access-layer/src/members/queryCache.ts
Copilot AI review requested due to automatic review settings July 14, 2026 12:42

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/data-access-layer/src/members/base.ts
Copilot AI review requested due to automatic review settings July 14, 2026 15:53

Copilot AI 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.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 7 comments.

Comment thread backend/src/database/repositories/segmentRepository.ts Outdated
Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/data-access-layer/src/members/base.ts
Comment thread frontend/src/modules/overview/components/fragments/project-group-filter.vue Outdated
Comment thread frontend/src/modules/lf/segments/store/actions.js Outdated
Comment thread backend/src/database/repositories/segmentRepository.ts Outdated
Comment thread backend/src/database/repositories/segmentRepository.ts Outdated
Copilot AI review requested due to automatic review settings July 14, 2026 16:30

Copilot AI 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.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.

Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/data-access-layer/src/members/base.ts
Comment thread backend/src/database/repositories/segmentRepository.ts Outdated
Comment thread services/libs/data-access-layer/src/members/queryCache.ts
Copilot AI review requested due to automatic review settings July 14, 2026 16:36

Copilot AI 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.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 8 comments.

Comment thread backend/src/database/repositories/segmentRepository.ts Outdated
Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/data-access-layer/src/members/base.ts
Comment thread frontend/src/utils/segments.js Outdated
Comment thread frontend/src/modules/lf/segments/store/actions.js Outdated
Comment thread frontend/src/modules/lf/segments/store/actions.js Outdated
Comment thread frontend/src/modules/overview/components/fragments/project-group-filter.vue Outdated
Comment thread backend/src/database/repositories/segmentRepository.ts Outdated
Copilot AI review requested due to automatic review settings July 14, 2026 16:48

Copilot AI 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.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.

Comment thread frontend/src/shared/project-column/lf-project-column.vue Outdated
Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/data-access-layer/src/members/base.ts
Comment thread services/libs/redis/src/index.ts
Copilot AI review requested due to automatic review settings July 14, 2026 16:58

Copilot AI 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.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.

Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/data-access-layer/src/members/base.ts
}

this.selectedProjectGroup = projectGroup;
this.fetchSubprojectsForProjectGroup(projectGroup.slug);
Comment thread frontend/src/modules/lf/segments/types/Segments.ts Outdated
Comment thread frontend/src/modules/activity/components/activity-timeline.vue Outdated
Copilot AI review requested due to automatic review settings July 15, 2026 09:44
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
@ulemons ulemons force-pushed the fix/debuging-query-members branch from f16f05a to 60042d7 Compare July 15, 2026 09:52

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread services/libs/redis/src/singleFlight.ts
Comment thread services/libs/data-access-layer/src/members/base.ts
Copilot AI review requested due to automatic review settings July 15, 2026 09:52

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread services/libs/data-access-layer/src/members/base.ts
Comment thread services/libs/redis/src/singleFlight.ts
@ulemons ulemons marked this pull request as ready for review July 15, 2026 10:06
@cursor

cursor Bot commented Jul 15, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes locking and concurrency on a high-traffic members list path; mis-tuned TTL/wait could still allow duplicate queries, and the activityCount gate changes which SQL path large paginated/export requests use.

Overview
Prevents cache-miss stampedes on members advanced queries by routing synchronous DB work through a new Redis withSingleFlight helper: one request holds the lock and runs the query; others poll the cache until it fills or the wait window ends (90s lock TTL aligned with wait timeout).

Background refreshes now use the same lock key and acquireLock/releaseLock primitives as the miss path (non-blocking try), replacing MemberQueryCache’s separate refresh-lock helpers so hit-triggered refresh and miss-triggered compute cannot duplicate the same heavy query.

Query behavior fixes: the main list query no longer forces the member-orgs join when orgs are loaded separately; the activityCount top-N path falls back to the full query when limit/offset (with oversampling) would exceed the shared 50k cap, avoiding silent truncation on large exports.

Reviewed by Cursor Bugbot for commit 60042d7. Bugbot is set up for automated code reviews on this repo. Configure here.

@ulemons ulemons merged commit 3f4a78e into main Jul 15, 2026
16 checks passed
@ulemons ulemons deleted the fix/debuging-query-members branch July 15, 2026 10:07

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 60042d7. Configure here.

})
return await withSingleFlight(
redis,
computeLockKey,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Compute locks survive invalidation

Medium Severity

Single-flight and background refresh now take Redis mutexes on unprefixed cache key strings via acquireLock, but MemberQueryCache invalidation still only deletes locks under the members-refresh-lock cache prefix. After cache invalidation, leftover compute locks can block repopulation for up to the 90s TTL.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 60042d7. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Created by Linear-GitHub Sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants