Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: f2f4682 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
Duplicate code analysis1 new clone introduced by this PR.
If one of these duplicates a helper that already exists, import it instead jscpd compared this branch against |
PR Review
2 finding(s): 🔴 0 critical · 🟠 1 major · 🔵 1 minor 2 posted as inline comment(s) on the changed lines. Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. The refactor (extract 🟡 P2 -- recommended
🔵 P3 nitpicks (4)
Reviewers (6): correctness, performance, kieran-typescript, testing, maintainability, previous-comments. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results✅ All tests passed • 465 passed • 1 skipped • 1180s
Tests ran across 4 shards in parallel. |
f41fccd to
f2f4682
Compare
Summary
Concurrent
getMapKeyscalls with the same arguments now share one ClickHouse query.The problem
getMapKeyschecked its cache withcache.get, ran the query, and stored the result withcache.setonly after the query finished. A second call with the same arguments that arrived while the first was still running found nothing in the cache and sent its own query.cache.getOrFetchshares running requests, butgetMapKeysonly used it on its last fallback (the raw table scan), not on the text index or rollup paths.On a 537M-row
otel_logstable (26 parts, ClickHouse 26.6), opening the search page ran every Map key text index read twice, at the same time:idx_log_attr_keyidx_res_attr_keyThat is about 47 GiB of memory in use at once for one user opening one page. With this change each read runs once.
Which two callers overlap isn't confirmed. The search page's field lookups build the same React Query key, which React Query already shares, so the duplicates need two keys that differ only in values
getMapKeysignores. A likely candidate isuseMultipleAllFields: its key includes thetimestampValueExpressionoption, butgetAllFieldsfalls back to the table connection's own value. If that option isundefinedon the first render, the key changes once the source loads, whilegetMapKeysgets the same arguments both times.getAllFieldsdoesn't pass React Query's abort signal on, so the first query keeps running. That's a separate fix.The fix
MetadataCache.dedupe(key, fn)shares one running call per key without caching its result.getOrFetchnow uses it, with no change in behavior.getMapKeyswraps its lookup (queryMapKeys) indedupe. What gets cached, and under which key, is unchanged frommain. The in-flight key includes the aligned date range: withouttimestampValueExpression,cacheKeyhas no range, but a rollup answer depends on it, so lookups for different ranges never share a rollup read.Known limit, same as every other
getOrFetchlookup: a shared read uses the first caller's abort signal, so if that caller aborts, the others get the rejection too.getAllFields, the search page path, passes no signal, so this only applies to direct callers such as the MCPdescribeSourcetool.Reading the keys index across every part is still expensive. A follow-up (#3418) reads a sample of parts instead.
How to reproduce
Starting point:
yarn devagainst a ClickHouse 26.3+ table with a Map key text index (e.g.idx_log_attr_key).On
main:SYSTEM FLUSH LOGS, then:On this branch:
References