Browse Source

Merge branch 'optimise-indexer' of CoBox/kappa-drive into master

peg 2 years ago
parent
commit
9717a38159
2 changed files with 11 additions and 4 deletions
  1. 11
    2
      index.js
  2. 0
    2
      test/index.test.js

+ 11
- 2
index.js View File

@@ -58,6 +58,7 @@ class KappaDrive extends EventEmitter {
58 58
     this._resolveFork = opts.resolveFork || vectorClock || numberLinks
59 59
     this._opts = opts
60 60
     this.core = this._opts.core || kappa(storage, Object.assign({ encryptionKey: key }, this._opts))
61
+    this._nonStateFeeds = []
61 62
     this._fileDescriptors = {}
62 63
     this._drives = {}
63 64
     this.vectorClock = {}
@@ -498,6 +499,10 @@ class KappaDrive extends EventEmitter {
498 499
 
499 500
     // TODO: drive = opts.version ? drive.checkout(opts.version) : drive
500 501
     this._drives[metadata.key] = drive
502
+
503
+    if (this._nonStateFeeds.indexOf(metadata.key.toString('hex')) < 0) this._nonStateFeeds.push(metadata.key.toString('hex'))
504
+    if (this._nonStateFeeds.indexOf(content.key.toString('hex')) < 0) this._nonStateFeeds.push(content.key.toString('hex'))
505
+
501 506
     drive.ready(() => callback(null, drive))
502 507
   }
503 508
 
@@ -596,14 +601,18 @@ class KappaDrive extends EventEmitter {
596 601
 
597 602
   _createMap () {
598 603
     var self = this
604
+    var nonStateFeeds = this._nonStateFeeds
599 605
     var ownKey = this.metadata.key
600 606
     self.vectorClock[ownKey.toString('hex')] = self.vectorClock[ownKey.toString('hex')] || 0
601 607
 
602 608
     return function (msg, next) {
603 609
       var ops = []
604 610
 
605
-      try { var state = State.decode(msg.value) }
606
-      catch (err) { return next() }
611
+      if (nonStateFeeds.indexOf(msg.key) > -1) return next()
612
+
613
+      try {
614
+        var state = State.decode(msg.value)
615
+      } catch (err) { return next() }
607 616
 
608 617
       if (state.metadata.id !== ownKey) {
609 618
         self.vectorClock[ownKey.toString('hex')] += 1

+ 0
- 2
test/index.test.js View File

@@ -2,8 +2,6 @@ const { describe } = require('tape-plus')
2 2
 const ram = require('random-access-memory')
3 3
 const crypto = require('hypercore-crypto')
4 4
 const fs = require('fs')
5
-const multifeed = require('multifeed')
6
-const hypercore = require('hypercore')
7 5
 
8 6
 const KappaDrive = require('../')
9 7