Commit ae929db
committed
Restore per-tenant grouping for batch existing-doc lookups in tenantPerDocument
When inlining find() per Jake's review, the per-tenant grouping the
deleted fetchExistingByIds helper used to do was lost. In tenantPerDocument
mode with a multi-tenant batch, the inlined find() runs under the session
tenant context (often null for platform workers) and silently misses rows
belonging to other tenants — every input doc looks "new" and goes down the
create path instead of the update path.
This actively breaks appwrite's StatsUsage worker, which accumulates stats
across many projects (each tagged with its own $tenant) and flushes them
via $dbForLogs->setTenant(null)->setTenantPerDocument(true) followed by
upsertDocumentsWithIncrease(...). With the old per-doc getDocument loop,
each lookup ran under withTenant($doc->getTenant()) and was correct. The
batch find() inlining lost that scoping.
Fix per Greptile's suggestion: branch on tenantPerDocument mode and run
one find() per unique tenant value under withTenant, merging results into
the same lookup hash. K queries (K = unique tenants in the batch) instead
of N (per-doc) or 1 (broken). Common single-tenant case still hits the
fast batched path.
Applied at both call sites:
- Database::createDocuments skipDuplicates pre-filter
- Database::upsertDocumentsWithIncrease existing-docs lookup
Fixes greptile flag at PR #852 discussion r3077481595.1 parent e9e5e76 commit ae929db
1 file changed
Lines changed: 87 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5695 | 5695 | | |
5696 | 5696 | | |
5697 | 5697 | | |
5698 | | - | |
5699 | | - | |
5700 | | - | |
5701 | | - | |
5702 | | - | |
5703 | | - | |
5704 | | - | |
5705 | | - | |
5706 | | - | |
5707 | | - | |
5708 | | - | |
5709 | | - | |
5710 | | - | |
5711 | | - | |
5712 | | - | |
5713 | | - | |
5714 | | - | |
| 5698 | + | |
| 5699 | + | |
| 5700 | + | |
| 5701 | + | |
| 5702 | + | |
| 5703 | + | |
| 5704 | + | |
| 5705 | + | |
| 5706 | + | |
| 5707 | + | |
| 5708 | + | |
5715 | 5709 | | |
5716 | | - | |
5717 | | - | |
5718 | | - | |
5719 | | - | |
5720 | | - | |
| 5710 | + | |
| 5711 | + | |
| 5712 | + | |
| 5713 | + | |
| 5714 | + | |
| 5715 | + | |
| 5716 | + | |
| 5717 | + | |
| 5718 | + | |
| 5719 | + | |
| 5720 | + | |
| 5721 | + | |
| 5722 | + | |
| 5723 | + | |
| 5724 | + | |
| 5725 | + | |
| 5726 | + | |
| 5727 | + | |
| 5728 | + | |
| 5729 | + | |
| 5730 | + | |
| 5731 | + | |
| 5732 | + | |
| 5733 | + | |
| 5734 | + | |
| 5735 | + | |
5721 | 5736 | | |
| 5737 | + | |
| 5738 | + | |
| 5739 | + | |
5722 | 5740 | | |
5723 | 5741 | | |
| 5742 | + | |
| 5743 | + | |
| 5744 | + | |
| 5745 | + | |
| 5746 | + | |
| 5747 | + | |
| 5748 | + | |
5724 | 5749 | | |
5725 | 5750 | | |
5726 | 5751 | | |
| |||
7189 | 7214 | | |
7190 | 7215 | | |
7191 | 7216 | | |
7192 | | - | |
7193 | | - | |
7194 | | - | |
7195 | | - | |
7196 | | - | |
7197 | | - | |
| 7217 | + | |
| 7218 | + | |
| 7219 | + | |
| 7220 | + | |
7198 | 7221 | | |
7199 | | - | |
7200 | | - | |
7201 | | - | |
7202 | | - | |
7203 | | - | |
7204 | | - | |
7205 | | - | |
7206 | | - | |
7207 | | - | |
| 7222 | + | |
| 7223 | + | |
| 7224 | + | |
| 7225 | + | |
| 7226 | + | |
| 7227 | + | |
| 7228 | + | |
| 7229 | + | |
| 7230 | + | |
| 7231 | + | |
| 7232 | + | |
| 7233 | + | |
| 7234 | + | |
| 7235 | + | |
| 7236 | + | |
| 7237 | + | |
| 7238 | + | |
| 7239 | + | |
| 7240 | + | |
| 7241 | + | |
| 7242 | + | |
| 7243 | + | |
| 7244 | + | |
| 7245 | + | |
| 7246 | + | |
| 7247 | + | |
| 7248 | + | |
| 7249 | + | |
| 7250 | + | |
| 7251 | + | |
| 7252 | + | |
| 7253 | + | |
| 7254 | + | |
| 7255 | + | |
| 7256 | + | |
| 7257 | + | |
7208 | 7258 | | |
7209 | 7259 | | |
7210 | 7260 | | |
| |||
0 commit comments