1111// 対象外(公開レコード前提)。
1212
1313import { getLogger } from "@logtape/logtape" ;
14+ import type { SignedDocument } from "@concrnt/client" ;
1415
1516import concrntApi from "./concrnt.ts" ;
1617import { config } from "./config.ts" ;
@@ -109,7 +110,13 @@ export const getLocalFollowerCcids = (actorURI: string): string[] =>
109110
110111interface LoadedRecord { key : string , schema : string , value : any , author : string , createdAt : string }
111112
112- // query APIはlimit上限100・sinceは閉区間なので、キーで重複排除しながらページングする
113+ // query APIのレスポンス封筒。@concrnt/client 2.0.1 の型定義は旧配列形式のままなので
114+ // クライアント更新までの間、ここで型を補う。
115+ interface QueryPage { items : SignedDocument [ ] , prev : string | null , next : string | null }
116+
117+ // nextカーソルが尽きるまでページングする。sinceは閉区間なので境界行が重複して
118+ // 返るため、キーで重複排除する。itemsは読取権限フィルタ後の内容なので、
119+ // 空ページでもnextがあれば継続する必要がある。
113120const queryAllByPrefix = async ( prefix : string , schema : string ) : Promise < LoadedRecord [ ] > => {
114121 const results = new Map < string , LoadedRecord > ( ) ;
115122 let since : string | undefined = undefined ;
@@ -118,21 +125,17 @@ const queryAllByPrefix = async (prefix: string, schema: string): Promise<LoadedR
118125 const page = await concrntApi . query (
119126 { prefix, schema, limit : 100 , order : 'asc' , since } ,
120127 config . concrnt . domain ,
121- ) ;
128+ ) as unknown as QueryPage ;
122129
123- let newCount = 0 ;
124- let lastCreatedAt : string | undefined = since ;
125- for ( const sd of page ) {
130+ for ( const sd of page . items ) {
126131 const doc = JSON . parse ( sd . document ) ;
127132 const key = sd . cckv ;
128133 if ( ! key ) continue ;
129- if ( ! results . has ( key ) ) newCount ++ ;
130134 results . set ( key , { key, schema : doc . schema , value : doc . value , author : doc . author , createdAt : doc . createdAt } ) ;
131- lastCreatedAt = doc . createdAt ;
132135 }
133136
134- if ( page . length < 100 || newCount === 0 ) break ;
135- since = lastCreatedAt ;
137+ if ( page . next === null || page . next === since ) break ;
138+ since = page . next ;
136139 }
137140
138141 return [ ...results . values ( ) ] ;
0 commit comments