mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-15 20:52:01 +03:00
fix(app): prioritize first transcript pages over background reads (#57741)
This commit is contained in:
committed by
GitHub
Unverified
parent
5798a4087a
commit
1ef252d1a4
@@ -102,15 +102,22 @@ describe("createRequestQueue", () => {
|
||||
expect(input.queue.inflight()).toBe(0)
|
||||
})
|
||||
|
||||
test("writes, then session lists, take the next free slot ahead of queued reads, each tier in order", async () => {
|
||||
test("writes, then navigation reads, take the next free slot in order without promoting history or indexes", async () => {
|
||||
const input = setup({ limit: 1 })
|
||||
|
||||
const requests: [string, string][] = [
|
||||
["GET", "/api/a"],
|
||||
["GET", "/api/b"],
|
||||
["GET", "/api/session/ses_1/message?cursor=older&order=desc"],
|
||||
["GET", "/api/session/ses_1/message?limit=25&before=msg_1"],
|
||||
["GET", "/api/session/ses_1/message?type=user&order=desc"],
|
||||
["GET", "/api/session/ses_1/message?order=asc"],
|
||||
["GET", "/api/session/ses_1/message/msg_1"],
|
||||
["GET", "/api/session?limit=1"],
|
||||
["GET", "/api/session/ses_1/message?limit=40&order=desc"],
|
||||
["POST", "/api/session/ses_1/message"],
|
||||
["GET", "/api/session?limit=2"],
|
||||
["GET", "/api/session/ses_2/message"],
|
||||
["DELETE", "/api/session/ses_2"],
|
||||
["GET", "/api/session/ses_1"],
|
||||
]
|
||||
@@ -128,8 +135,15 @@ describe("createRequestQueue", () => {
|
||||
"/api/session/ses_1/message",
|
||||
"/api/session/ses_2",
|
||||
"/api/session?limit=1",
|
||||
"/api/session/ses_1/message?limit=40&order=desc",
|
||||
"/api/session?limit=2",
|
||||
"/api/session/ses_2/message",
|
||||
"/api/b",
|
||||
"/api/session/ses_1/message?cursor=older&order=desc",
|
||||
"/api/session/ses_1/message?limit=25&before=msg_1",
|
||||
"/api/session/ses_1/message?type=user&order=desc",
|
||||
"/api/session/ses_1/message?order=asc",
|
||||
"/api/session/ses_1/message/msg_1",
|
||||
"/api/session/ses_1",
|
||||
])
|
||||
await Promise.all(responses)
|
||||
|
||||
@@ -120,14 +120,20 @@ export function createRequestQueue(input: {
|
||||
const fetch: typeof globalThis.fetch = Object.assign(
|
||||
async (resource: RequestInfo | URL, init?: RequestInit) => {
|
||||
const request = new Request(resource, init)
|
||||
const pathname = new URL(request.url).pathname
|
||||
const url = new URL(request.url)
|
||||
const pathname = url.pathname
|
||||
|
||||
// The event stream is long-lived; never count it against the request budget.
|
||||
if (pathname === "/api/event") return base(request)
|
||||
// Writes (prompt sends, replies, edits) are the user's own actions and never wait behind reads. Listing sessions is
|
||||
// one indexed database read that Home shows nothing without, so it goes ahead of queued location reads, which can
|
||||
// each wait seconds on a location the server is still loading.
|
||||
const priority = request.method !== "GET" ? 2 : pathname === "/api/session" ? 1 : 0
|
||||
// Writes go first. Session lists and the first transcript page unblock navigation, so they
|
||||
// go ahead of location reads. Older pages and filtered indexes keep background priority.
|
||||
const initialMessages =
|
||||
/^\/api\/session\/[^/]+\/message$/.test(pathname) &&
|
||||
!url.searchParams.has("cursor") &&
|
||||
!url.searchParams.has("before") &&
|
||||
!url.searchParams.has("type") &&
|
||||
url.searchParams.get("order") !== "asc"
|
||||
const priority = request.method !== "GET" ? 2 : pathname === "/api/session" || initialMessages ? 1 : 0
|
||||
const entry = { method: request.method, url: request.url, at: now(), slow: isSlowRequest(pathname), priority }
|
||||
const queued = acquire(entry)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user