Skip to content

Commit

Permalink
unique cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jchris committed Jun 5, 2024
1 parent daa24ba commit 3eea967
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 188 deletions.
27 changes: 6 additions & 21 deletions packages/encrypted-blockstore/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,22 @@ import { DataStore as AbstractDataStore, MetaStore as AbstractMetaStore } from '
import type { CarTransaction } from './transaction'
import { CommitQueue } from './commit-queue'

//Fix this
export function cidListIncludes(list: CarLog, cids: CarGroup) {
//Here we are checking if the carlog has the cars present inside the meta object
const checkequality = (arr: CarGroup) => {
return list.some((arr: CarGroup) => {
return arr.toString() === cids.toString()
}

return list.some(checkequality)
})
}
export function uniqueCids(list: CarLog, remove: Set<string> = new Set()): AnyLink[][] {

// this works for car groups because toString looks like bafy,bafy
function uniqueCids(list: CarLog, remove: Set<string> = new Set()): AnyLink[][] {
const byString = new Map<string, AnyLink[]>()
// ? Do we wanna remove one segment at a time or the whole list?
for (const cid of list) {
if (remove.has(cid.toString())) continue
byString.set(cid.toString(), cid)
}
return [...byString.values()]
}

export function uniqueCarCids(list: CarLog, remove: Set<string> = new Set()): AnyLink[][] {
const byString = new Map<string, AnyLink[]>()
// ? Do we wanna remove one segment at a time or the whole list?
for (const carcids of list) {
for (const cid of carcids) {
if (remove.has(cid.toString())) continue
byString.set(cid.toString(), [cid])
}
}
return [...byString.values()]
}

export function toHexString(byteArray: Uint8Array) {
return Array.from(byteArray)
.map(byte => byte.toString(16).padStart(2, '0'))
Expand Down Expand Up @@ -309,7 +294,7 @@ export class Loader implements Loadable {
const previousCompactCid = fp.compact[fp.compact.length - 1]
fp.compact.map(c => c.toString()).forEach(this.seenCompacted.add, this.seenCompacted)
//Made the change here from uniqueCids to uniqueCarCids
this.carLog = [...uniqueCarCids([...this.carLog, ...fp.cars, cids], this.seenCompacted)]
this.carLog = [...uniqueCids([...this.carLog, ...fp.cars, cids], this.seenCompacted)]
void this.removeCidsForCompact(previousCompactCid[0])
} else {
//Work on this and make sure the tests pass
Expand Down
Loading

0 comments on commit 3eea967

Please sign in to comment.