request-history: per-key query uses idx_requests_api_key + temp B-tree sort; 0.4-0.9 s per page live, 22 s on a cold copy (needs (api_key_id, timestamp DESC, request_id DESC))
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- sqlite, typescript
- 領域
- databases
調査の方向性
Start with queryRows in src/routing/history/indexer.ts and the index definitions in src/routing/history/schema.ts, including HISTORY_SCHEMA_VERSION. Run EXPLAIN QUERY PLAN on the per-key query against a test database to confirm the current index and temp B-tree sort. Done when the plan uses a compound (api_key_id, timestamp DESC, request_id DESC) index with no temp sort and the rows come back in the same order. Whether a schema bump or rebuild is needed is a maintainer decision.
索引モデルが issue の本文から書いたものです。
説明
Client or integration
Direct HTTP/API client
Area
Proxy and routing
Summary
The request-history query filtered by API key is slow on a large history database: 0.4-0.9 s per page live, and 22 s on a cold copy. It plans on idx_requests_api_key plus a temporary B-tree sort, so every page reads and sorts all of that key's rows and then keeps limit+1. I expected a per-key page to cost about the same as an unfiltered page. A compound index (api_key_id, timestamp DESC, request_id DESC) makes it 0.0-0.1 ms for every key size I tested, with the same rows in the same order.
Reproduction
- Use a
routing-history.sqliteof about 12.6 GB with nosqlite_stat1(ANALYZE never run). - Call the request-history query with
apiKeyIdandfrom/to(src/routing/history/indexer.ts,queryRows):
SELECT row_json, timestamp, request_id FROM requests WHERE api_key_id = ? AND timestamp >= ? AND timestamp <= ? ORDER BY timestamp DESC, request_id DESC LIMIT ? EXPLAIN QUERY PLANgives:SEARCH requests USING INDEX idx_requests_api_key (api_key_id=?)andUSE TEMP B-TREE FOR ORDER BY.
Measured, best of 2-3 runs, with the same rows returned in every arm:
- A key with 32,777 rows in 7 days (214,279 in total): 392-454 ms per page on the live database.
- A key with 104,099 rows in 7 days (360,394 in total): 880 ms live, and 22,508 ms on a cold copy.
- Forcing
idx_requests_ts: 0.1-1.0 ms on those two keys, but 474-945 ms on a 1-row key. - After
ANALYZE, the planner picksidx_requests_tsfor every key, so sparse keys become slow. CREATE INDEX idx_requests_key_ts ON requests(api_key_id, timestamp DESC, request_id DESC): 0.0-0.1 ms for keys of 1, 15, 337, 2,290 and 104,099 rows. It took 28.8 s to build and added 245 MB to the 12.6 GB database.
Proposed change: add that compound index in src/routing/history/schema.ts, and bump HISTORY_SCHEMA_VERSION if a rebuild is the migration path. The same pattern probably applies to the conversation_id and profile_id filters.
Version
Measured on 2.100.6. As of 2.100.8 and dev today, schema.ts still defines only idx_requests_api_key ON requests(api_key_id).
Operating system
macOS
Provider and model
Not provider-specific.
Logs or error output
SEARCH requests USING INDEX idx_requests_api_key (api_key_id=?)
USE TEMP B-TREE FOR ORDER BY
Checks
- I searched existing issues and documentation.
- I removed secrets, tokens, account details, request credentials, and personal data.
- 主要言語
- TypeScript
- スター
- 16.9k
- フォーク
- 1.3k
- 平均マージ
- 1日 4時間
- マージ済み PR(30日)
- 814
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
lidge-jun/opencodex のほかの issue
-
bug gui platform
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
lidge-jun/opencodex#9172 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Feature]: Include provider, model and account label in the `upstream failure` service.log line対応中かも @EnesKartal が 4 日前に担当しました。 オープンenhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
lidge-jun/opencodex#9057 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Provider] antigravity-acp catalog omits gemini-4-hydrogen and gemini-4-neon that agy acp offers対応中かも @sedoll が 6 日前に担当しました。 オープンcatalog provider provider-compatibility
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
lidge-jun/opencodex#9037 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug cli
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
lidge-jun/opencodex#9171 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
account-pool enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
lidge-jun/opencodex の issue をすべて見る
似ている issue
-
manually bump balena-preload to ^19.0.6対応中かも @shaunmulligan が今日担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 66/100
balena-io/balena-cli#3200 ·
メンテナーはふだん 1 日以内に返信
-
`MaterializedChatMessage._text` is quadratic in the number of text chunks (`+=` followed by `endsWith`), driving the extension host to heap OOM対応中かも @olegius88 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
microsoft/vscode-prompt-tsx#205 ·
-
triage
難易度 1/5 1時間未満 初心者へのやさしさ 64/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
melgarafael/DeskcommCRM#5340 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
ehmpathy/rhachet-roles-ehmpathy#1529 ·
メンテナーはふだん 1 日以内に返信