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

Sign up to get free protection for your applications and to get access to all the features.
@@ -89,10 +89,12 @@ export class Base {
89
89
  const block = await this.getLoaderBlock(cid);
90
90
  allBlocks.set(cid, block);
91
91
  }
92
+ cidMap.clear();
92
93
  const blocks = {
93
94
  lastCid: clock[0],
94
95
  get: cid => allBlocks.get(cid.toString())
95
96
  };
97
+ console.log('compact', this.instanceId, this.name, blocks.lastCid.toString(), dataCids.length);
96
98
  await this.parkCar(blocks, dataCids);
97
99
  }
98
100
  async parkCar(innerBlockstore, cids) {
@@ -230,6 +232,7 @@ export class Base {
230
232
  }
231
233
  async mapForIPLDHashmapCarCid(carCid) {
232
234
  // console.log('mapForIPLDHashmapCarCid', carCid)
235
+ // todo why is this writeable?
233
236
  const carMapReader = await this.getWriteableCarReader(carCid);
234
237
  const indexNode = await load(carMapReader, carMapReader.root.cid, {
235
238
  blockHasher: blockOpts.hasher,
@@ -268,7 +271,19 @@ export class Base {
268
271
  };
269
272
  return combinedReader;
270
273
  }
274
+ async xgetCarReader(carCid) {
275
+ return this.getCarReaderImpl(carCid);
276
+ }
277
+ carReaderCache = new Map();
271
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) {
272
287
  carCid = carCid.toString();
273
288
  const carBytes = await this.readCar(carCid);
274
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.5",
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",
@@ -99,10 +99,12 @@ export class Base {
99
99
  const block = await this.getLoaderBlock(cid)
100
100
  allBlocks.set(cid, block)
101
101
  }
102
+ cidMap.clear()
102
103
  const blocks = {
103
104
  lastCid: clock[0],
104
105
  get: cid => allBlocks.get(cid.toString())
105
106
  }
107
+ console.log('compact', this.instanceId, this.name, blocks.lastCid.toString(), dataCids.length)
106
108
  await this.parkCar(blocks, dataCids)
107
109
  }
108
110
 
@@ -248,6 +250,7 @@ export class Base {
248
250
 
249
251
  async mapForIPLDHashmapCarCid (carCid) {
250
252
  // console.log('mapForIPLDHashmapCarCid', carCid)
253
+ // todo why is this writeable?
251
254
  const carMapReader = await this.getWriteableCarReader(carCid)
252
255
  const indexNode = await load(carMapReader, carMapReader.root.cid, {
253
256
  blockHasher: blockOpts.hasher,
@@ -286,7 +289,21 @@ export class Base {
286
289
  return combinedReader
287
290
  }
288
291
 
292
+ async xgetCarReader (carCid) {
293
+ return this.getCarReaderImpl(carCid)
294
+ }
295
+
296
+ carReaderCache = new Map()
289
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) {
290
307
  carCid = carCid.toString()
291
308
  const carBytes = await this.readCar(carCid)
292
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
  *