Skip to content

Commit

Permalink
Fix possible null error in revision tracker.
Browse files Browse the repository at this point in the history
  • Loading branch information
saul-jb committed Mar 6, 2024
1 parent 6f46542 commit a57ed13
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/daemon/src/modules/revisions/sync-revisions.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import Path from 'path'
import * as dagCbor from '@ipld/dag-cbor'
import { VERSION_KEY } from './interface.js'
import { VERSION_KEY, EncodedEntry } from './interface.js'
import { decodeEntry } from './utils.js'
import { type Requires, logger } from './index.js'

export default async ({ groups, downloader }: Requires): Promise<void> => {
for (const { value: database } of groups.groups.all()) {
const tracker = groups.getTracker(database)
const group = database.manifest.address.cid

for await (const { key, value } of tracker.process(`/${VERSION_KEY}`)) {
const entry = decodeEntry(dagCbor.decode(value))
const group = database.manifest.address.cid
const data = EncodedEntry.parse(dagCbor.decode(value))
const fullKey = Path.join('/', group.toString(), key)

logger.info('[entry] syncing update:', fullKey)

if (entry == null) {
if (data == null) {
await downloader.pinManager.remove(fullKey)
continue
}

const entry = decodeEntry(data)

logger.info('[entry] syncing update:', fullKey)

await downloader.pinManager.put(fullKey, { cid: entry.cid, priority: entry.priority })
}
}
Expand Down

0 comments on commit a57ed13

Please sign in to comment.