@fireproof/core 0.7.2-dev.6 → 0.7.2-dev.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -94,6 +94,7 @@ export class Base {
94
94
  lastCid: clock[0],
95
95
  get: cid => allBlocks.get(cid.toString())
96
96
  };
97
+ console.log('compact', this.instanceId, this.name, blocks.lastCid.toString(), dataCids.length);
97
98
  await this.parkCar(blocks, dataCids);
98
99
  }
99
100
  async parkCar(innerBlockstore, cids) {
@@ -231,6 +232,7 @@ export class Base {
231
232
  }
232
233
  async mapForIPLDHashmapCarCid(carCid) {
233
234
  // console.log('mapForIPLDHashmapCarCid', carCid)
235
+ // todo why is this writeable?
234
236
  const carMapReader = await this.getWriteableCarReader(carCid);
235
237
  const indexNode = await load(carMapReader, carMapReader.root.cid, {
236
238
  blockHasher: blockOpts.hasher,
@@ -269,7 +271,19 @@ export class Base {
269
271
  };
270
272
  return combinedReader;
271
273
  }
274
+ async xgetCarReader(carCid) {
275
+ return this.getCarReaderImpl(carCid);
276
+ }
277
+ carReaderCache = new Map();
272
278
  async getCarReader(carCid) {
279
+ if (this.carReaderCache.has(carCid)) {
280
+ return this.carReaderCache.get(carCid);
281
+ }
282
+ const result = await this.getCarReaderImpl(carCid);
283
+ this.carReaderCache.set(carCid, result);
284
+ return result;
285
+ }
286
+ async getCarReaderImpl(carCid) {
273
287
  carCid = carCid.toString();
274
288
  const carBytes = await this.readCar(carCid);
275
289
  // console.log('getCarReader', this.constructor.name, carCid, carBytes.length)
package/dist/valet.js CHANGED
@@ -49,18 +49,6 @@ export class Valet {
49
49
  throw new Error('missing lastCid for car header');
50
50
  }
51
51
  }
52
- // async compact() {
53
- // const carCids = []
54
- // // for await (const { cid } of this.valet.cids()) {
55
- // // yield { cid }
56
- // // }
57
- // // create a blockstore with all data
58
- // {
59
- // entries: () => syncCIDs.map(cid => ({ cid })),
60
- // get: async cid => await blocks.get(cid)
61
- // }
62
- // // park it
63
- // }
64
52
  /**
65
53
  * Iterate over all blocks in the store.
66
54
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireproof/core",
3
- "version": "0.7.2-dev.6",
3
+ "version": "0.7.2-dev.7",
4
4
  "description": "Live data for React, accelerated by proofs, powered by IPFS",
5
5
  "main": "dist/src/fireproof.js",
6
6
  "module": "dist/src/fireproof.mjs",
@@ -104,6 +104,7 @@ export class Base {
104
104
  lastCid: clock[0],
105
105
  get: cid => allBlocks.get(cid.toString())
106
106
  }
107
+ console.log('compact', this.instanceId, this.name, blocks.lastCid.toString(), dataCids.length)
107
108
  await this.parkCar(blocks, dataCids)
108
109
  }
109
110
 
@@ -249,6 +250,7 @@ export class Base {
249
250
 
250
251
  async mapForIPLDHashmapCarCid (carCid) {
251
252
  // console.log('mapForIPLDHashmapCarCid', carCid)
253
+ // todo why is this writeable?
252
254
  const carMapReader = await this.getWriteableCarReader(carCid)
253
255
  const indexNode = await load(carMapReader, carMapReader.root.cid, {
254
256
  blockHasher: blockOpts.hasher,
@@ -287,7 +289,21 @@ export class Base {
287
289
  return combinedReader
288
290
  }
289
291
 
292
+ async xgetCarReader (carCid) {
293
+ return this.getCarReaderImpl(carCid)
294
+ }
295
+
296
+ carReaderCache = new Map()
290
297
  async getCarReader (carCid) {
298
+ if (this.carReaderCache.has(carCid)) {
299
+ return this.carReaderCache.get(carCid)
300
+ }
301
+ const result = await this.getCarReaderImpl(carCid)
302
+ this.carReaderCache.set(carCid, result)
303
+ return result
304
+ }
305
+
306
+ async getCarReaderImpl (carCid) {
291
307
  carCid = carCid.toString()
292
308
  const carBytes = await this.readCar(carCid)
293
309
  // console.log('getCarReader', this.constructor.name, carCid, carBytes.length)
package/src/valet.js CHANGED
@@ -52,19 +52,6 @@ export class Valet {
52
52
  }
53
53
  }
54
54
 
55
- // async compact() {
56
- // const carCids = []
57
- // // for await (const { cid } of this.valet.cids()) {
58
- // // yield { cid }
59
- // // }
60
- // // create a blockstore with all data
61
- // {
62
- // entries: () => syncCIDs.map(cid => ({ cid })),
63
- // get: async cid => await blocks.get(cid)
64
- // }
65
- // // park it
66
- // }
67
-
68
55
  /**
69
56
  * Iterate over all blocks in the store.
70
57
  *