Skip to content

Commit 114e484

Browse files
committed
fix: reuse authenticated fetch in ldhop to improve performance
1 parent 9d6da5f commit 114e484

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/utils.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ export const getBotFetch = async () => {
174174
/**
175175
* Fetch RDF document with notification bot identity, and return quads
176176
*/
177-
export const fetchRdf = async (uri: string) => {
178-
const authBotFetch = await getBotFetch()
177+
export const fetchRdf = async (
178+
uri: string,
179+
authFetch?: typeof globalThis.fetch,
180+
) => {
181+
const authBotFetch = authFetch ?? (await getBotFetch())
179182
const { data: quads } = await fetchRdfDocument(uri, authBotFetch)
180183
return quads
181184
}
@@ -186,11 +189,13 @@ export const fetchRdf = async (uri: string) => {
186189
const run = async (qas: QueryAndStore) => {
187190
let missingResources = qas.getMissingResources()
188191

192+
const authFetch = await getBotFetch()
193+
189194
while (missingResources.length > 0) {
190195
let quads: Quad[] = []
191196
const res = missingResources[0]
192197
try {
193-
quads = await fetchRdf(missingResources[0])
198+
quads = await fetchRdf(missingResources[0], authFetch)
194199
} catch (e) {
195200
// eslint-disable-next-line no-console
196201
console.error(e)

0 commit comments

Comments
 (0)