Skip to content

Commit

Permalink
feat: resolve local names using cache
Browse files Browse the repository at this point in the history
  • Loading branch information
tabcat committed Sep 16, 2023
1 parent 5886c84 commit f4b18bf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/namers/w3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,26 @@ const publish =
}

const resolve =
(service: W3NameService, revisions: RevisionState, localResolutions: boolean): Namer['resolve'] =>
(service: W3NameService, revisions: RevisionState): Namer['resolve'] =>
async (peerId: Ed25519PeerId) => {
let revision: Name.Revision | undefined = await revisions.get(peerId)

if (revision != null && localResolutions) {
if (revision != null) {
// keys must not be updated concurrently by other devices
return revision2cid(revision.value)
}

try {
revision = await Name.resolve(pid2Name(peerId), service)
return revision2cid(revision.value)
} catch {
throw new Error('unable to resolve peerId to value')
}

return revision2cid(revision.value)
}

export function w3Namer (service: W3NameService, revisions: RevisionState, options?: { localResolutions: boolean }): Namer {
export function w3Namer (service: W3NameService, revisions: RevisionState): Namer {
return {
publish: publish(service, revisions),
resolve: resolve(service, revisions, Boolean(options?.localResolutions))
resolve: resolve(service, revisions)
}
}

0 comments on commit f4b18bf

Please sign in to comment.