Skip to content

Reuse compiled queries across tenants - #26282

Merged
ismcagdas merged 2 commits into
rel-10.7from
maliming/tenant-query-cache
Oct 14, 2026
Merged

ismcagdas merged 2 commits into
rel-10.7from
maliming/tenant-query-cache

Conversation

@maliming

Copy link
Copy Markdown
Member

Resolve #26281

Remove the tenant ID from AbpDbContext.GetCompiledQueryCacheKey() and keep the data filter states in the key.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 02:38
@maliming maliming added this to the 10.7-final milestone Oct 14, 2026

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.

🟡 Changes recommended

Existing custom tenant-dependent query translations could silently reuse tenant-specific compiled SQL across tenants.

1 open finding
What changed in this PR

Updates EF Core compiled-query caching to reuse queries across tenants while retaining filter-state isolation.

Changes:

  • Removes tenant IDs from compiled-query cache keys.
  • Adds SQLite integration tests for tenant and filter isolation.
  • Covers both database-function and standard filter modes.
File Description
QueryCompilationCounter.cs Counts query compilations.
CompiledQueryCacheTestRow.cs Defines the test entity.
CompiledQueryCacheTestModuleWithoutDbFunction.cs Configures standard filters.
CompiledQueryCacheTestModuleBase.cs Configures and seeds SQLite tests.
CompiledQueryCacheTestModule.cs Enables database-function filters.
CompiledQueryCacheTestDbContext.cs Defines the test context.
CompiledQueryCacheTestBase.cs Tests cache reuse and data isolation.
CompiledQueryCache_WithoutDbFunction_Tests.cs Runs standard-filter tests.
CompiledQueryCache_Tests.cs Runs database-function tests.
AbpDbContext.cs Removes tenant IDs from cache keys.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@maliming
maliming marked this pull request as draft October 14, 2026 02:43
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0.34364% with 290 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.05%. Comparing base (98d0ef4) to head (57a0332).
⚠️ Report is 16 commits behind head on rel-10.7.

Files with missing lines Patch % Lines
...g/CompiledQueryCache/CompiledQueryCacheTestBase.cs 0.00% 111 Missing ⚠️
...iledQueryCache/TenantDependentTranslation_Tests.cs 0.00% 53 Missing ⚠️
...iledQueryCache/CompiledQueryCacheTestModuleBase.cs 0.00% 51 Missing ⚠️
...ryCache/TenantDependentTranslationTestDbContext.cs 0.00% 34 Missing ⚠️
...QueryCache/TenantDependentTranslationTestModule.cs 0.00% 24 Missing ⚠️
...piledQueryCache/CompiledQueryCacheTestDbContext.cs 0.00% 4 Missing ⚠️
...ring/CompiledQueryCache/QueryCompilationCounter.cs 0.00% 4 Missing ⚠️
...ng/CompiledQueryCache/CompiledQueryCacheTestRow.cs 0.00% 3 Missing ⚠️
...ledQueryCache/TenantDependentTranslationTestRow.cs 0.00% 2 Missing ⚠️
...CompiledQueryCache/CompiledQueryCacheTestModule.cs 0.00% 1 Missing ⚠️
... and 3 more
Additional details and impacted files
@@             Coverage Diff              @@
##           rel-10.7   #26282      +/-   ##
============================================
- Coverage     50.18%   50.05%   -0.13%     
============================================
  Files          3829     3842      +13     
  Lines        134139   134429     +290     
  Branches      10172    10199      +27     
============================================
- Hits          67311    67285      -26     
- Misses        64798    65131     +333     
+ Partials       2030     2013      -17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

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.

🟢 Approval recommended

The behavior is comprehensively tested across filter modes and the custom-translation compatibility requirement is clearly documented.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@maliming
maliming marked this pull request as ready for review October 14, 2026 05:14
@maliming
maliming requested a review from ismcagdas October 14, 2026 05:41
@ismcagdas
ismcagdas merged commit b1d3447 into rel-10.7 Oct 14, 2026
5 of 7 checks passed
@ismcagdas
ismcagdas deleted the maliming/tenant-query-cache branch October 14, 2026 05:55
ismcagdas added a commit that referenced this pull request Oct 15, 2026
…26284)

Related to #26282

With `UseDbFunction`, the soft delete and multi-tenant filter translations treated a missing current DbContext as a disabled filter, so `EF.CompileQuery` and `EF.CompileAsyncQuery` ran without these filters. They now throw an `AbpException`. ABP wraps `IDatabase` and only lets the query that went through the compiled query cache key generator read the current DbContext, so a nested compiled query can't use the outer query's filter state.
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.

3 participants