⚡ perf(vscode): 看板打开先出快照、评论只拉末页
This commit is contained in:
1 parent
904ab7491d
commit
a68caf5f6e
9 files changed
+447
-115
No files matched your search
+26
-11
@@ -13,7 +13,7 @@ import { Buffer } from 'node:buffer'
|
||||
|
||||
import { logger } from '../logging/logger'
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
export const PAGE_SIZE = 50
|
||||
|
||||
export interface GiteaUser {
|
||||
login: string
|
||||
@@ -226,6 +226,29 @@ export async function listAllRepoComments(opts: {
|
||||
return out
|
||||
}
|
||||
|
||||
/**
|
||||
* 单页拉取某工单评论。Gitea 默认旧→新,末页才是最新 state JSON 所在。
|
||||
*/
|
||||
export async function listIssueCommentsPage(opts: {
|
||||
host: string
|
||||
token: string
|
||||
owner: string
|
||||
repo: string
|
||||
index: number
|
||||
page: number
|
||||
}): Promise<GiteaComment[]> {
|
||||
const url = new URL(
|
||||
`${baseUrl(opts.host)}/repos/${opts.owner}/${opts.repo}/issues/${opts.index}/comments`,
|
||||
)
|
||||
url.searchParams.set('limit', String(PAGE_SIZE))
|
||||
url.searchParams.set('page', String(opts.page))
|
||||
|
||||
const res = await fetch(url.toString(), { headers: authHeaders(opts.token) })
|
||||
await ensureOk(res)
|
||||
const batch = await res.json() as GiteaComment[]
|
||||
return Array.isArray(batch) ? batch : []
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches comments for a single issue via
|
||||
* `/repos/{owner}/{repo}/issues/{index}/comments`. Paginated until a short
|
||||
@@ -243,16 +266,8 @@ export async function listIssueComments(opts: {
|
||||
let page = 1
|
||||
|
||||
while (true) {
|
||||
const url = new URL(
|
||||
`${baseUrl(opts.host)}/repos/${opts.owner}/${opts.repo}/issues/${opts.index}/comments`,
|
||||
)
|
||||
url.searchParams.set('limit', String(PAGE_SIZE))
|
||||
url.searchParams.set('page', String(page))
|
||||
|
||||
const res = await fetch(url.toString(), { headers: authHeaders(opts.token) })
|
||||
await ensureOk(res)
|
||||
const batch = await res.json() as GiteaComment[]
|
||||
if (!Array.isArray(batch) || batch.length === 0)
|
||||
const batch = await listIssueCommentsPage({ ...opts, page })
|
||||
if (batch.length === 0)
|
||||
break
|
||||
out.push(...batch)
|
||||
if (batch.length < PAGE_SIZE)
|
||||
|
||||
Reference in new issue
Block a user