Draft: Skip Redis in lock checks for projects without locks

What does this MR do and why?

The path lock and LFS lock mergeability checks read a cached result from Redis for every merge request, even when the check is inactive (the cached value is a constant) or the project has no locks at all. On merge request lists that is one or two Redis round trips per merge request for an answer that needs no I/O.

Behind mergeability_lock_checks_skip_redis, inactive checks and lock-free projects skip the results cache, and whether a project has locks is checked once per project per request. Projects with locks keep today's cached path.

On GitLab.com these two checks take about 4,000 seconds per hour (3.3%) of GET /groups/:id/merge_requests.

References

Screenshots or screen recordings

Not a UI change.

How to set up and validate locally

  1. Enable the flag in a Rails console:
    Feature.enable(:mergeability_lock_checks_skip_redis)
  2. Call the group list for a group with open merge requests, once with the flag on and once off, and compare the detailed_merge_status values. They should be identical:
    curl --header "PRIVATE-TOKEN: <token>" "http://gdk.test:3000/api/v4/groups/<id>/merge_requests?state=opened&per_page=100"
  3. Lock a file in one of the projects (Repository > Files > Lock) and repeat. Merge requests changing that file by another author report locked_paths, as before.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Detailed context for AI agents

Change

  • CheckPathLocksService#cacheable? (EE) and CheckLfsFileLocksService#cacheable? (CE) return false when the flag is on and either the check is inactive (no file_locks licence or target is not the default branch; LFS disabled) or the project has no locks. RunChecksService#run_check then calls execute directly, which answers inactive or success without Redis.
  • Lock presence (project.path_locks.exists?, project.lfs_file_locks.any?) is memoized in Gitlab::SafeRequestStore per project id, so a page with many merge requests of one project queries once. The service-level strong_memoize keeps cacheable? and execute on one instance to one lookup.
  • Projects with locks keep the existing cache key (merge request id, diff head sha, lock epoch) and TTL.
  • Flag off: master behaviour, apart from the Feature.enabled? call.

Before and after per merge request

  • Inactive check: before 1 Redis GET of a constant key (plus a SET when cold); after none.
  • Active check, project without locks: before 1 Redis GET for the lock epoch (not memoized) plus 1 GET for the cached result, and on a miss 1 SQL plus a SET; after 1 SQL per project per request.
  • Active check, project with locks: unchanged (1 SQL per project per request to decide, then today's cached path).

Staleness

The request-scoped memo means a lock created during the same request is not seen by later checks in that request. Lock and unlock requests (PathLocks::LockService, Lfs::LockFileService and their unlock counterparts) do not run mergeability checks afterwards, and today's epoch-keyed cache already relies on a per-request epoch read.

Verification

  • ee/spec/services/merge_requests/mergeability/check_path_locks_service_spec.rb and spec/services/merge_requests/mergeability/check_lfs_file_locks_service_spec.rb: #cacheable? for locked, lock-free and inactive cases, flag off, and a request-store example asserting zero queries for a second check of the same project. A mutation run without the memo fails that example.

Production context

Measured on GitLab.com (Kibana, 2026-10-19) for GET /api/:version/groups/:id/merge_requests:

  • About 139k requests and 122k seconds of request time per hour. The per-MR mergeability checks behind detailed_merge_status take 40.6k of those seconds (33%), read from the per-MR application_json lines that share the request's correlation_id (mergeability.<check>.duration_s.values).
  • Seconds per hour by check: commits_status 11,174, approved 9,148, security_policy_violations 8,238, conflict_status 4,157, path_locks 2,100, lfs_file_locks 1,980, discussions_status 1,453, rebase_status 1,317.
  • Most of the load comes from bots polling state=opened&per_page=100 every few minutes: 53% of the endpoint's server time, with typical pages spanning 30 to 90 projects.

The investigation and the other changes from it are tracked in #631601. This is one of four independent drafts, each behind its own gitlab_com_derisk flag.

Merge request reports

Loading
Loading