Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

update build #256

Merged
merged 1 commit into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dist/ipfslog.min.js

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions lib/es5/entry-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var EntryIndex =
/*#__PURE__*/
function () {
function EntryIndex() {
var entries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck2.default)(this, EntryIndex);
this._cache = entries;
}

(0, _createClass2.default)(EntryIndex, [{
key: "set",
value: function set(k, v) {
this._cache[k] = v;
}
}, {
key: "get",
value: function get(k) {
return this._cache[k];
}
}, {
key: "delete",
value: function _delete(k) {
return delete this._cache[k];
}
}, {
key: "add",
value: function add(newItems) {
this._cache = Object.assign(this._cache, newItems);
}
}, {
key: "length",
get: function get() {
return Object.values(this._cache).length;
}
}]);
return EntryIndex;
}();

module.exports = EntryIndex;
19 changes: 12 additions & 7 deletions lib/es5/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var _require2 = require('./utils'),
isDefined = _require2.isDefined,
findUniques = _require2.findUniques;

var EntryIndex = require('./entry-index');

var randomId = function randomId() {
return new Date().getTime().toString();
};
Expand Down Expand Up @@ -141,7 +143,7 @@ function (_GSet) {
_this._identity = identity; // Add entries to the internal cache

entries = entries || [];
_this._entryIndex = entries.reduce(uniqueEntriesReducer, {}); // Set heads if not passed as an argument
_this._entryIndex = new EntryIndex(entries.reduce(uniqueEntriesReducer, {})); // Set heads if not passed as an argument

heads = heads || Log.findHeads(entries);
_this._headsIndex = heads.reduce(uniqueEntriesReducer, {}); // Index of all next pointers in this log
Expand Down Expand Up @@ -180,7 +182,7 @@ function (_GSet) {
* @returns {Entry|undefined}
*/
value: function get(hash) {
return this._entryIndex[hash];
return this._entryIndex.get(hash);
}
/**
* Checks if a entry is part of the log
Expand All @@ -191,7 +193,7 @@ function (_GSet) {
}, {
key: "has",
value: function has(entry) {
return this._entryIndex[entry.hash || entry] !== undefined;
return this._entryIndex.get(entry.hash || entry) !== undefined;
}
}, {
key: "traverse",
Expand Down Expand Up @@ -298,7 +300,8 @@ function (_GSet) {
throw new Error("Could not append entry, key \"".concat(this._identity.id, "\" is not allowed to write to the log"));

case 13:
this._entryIndex[entry.hash] = entry;
this._entryIndex.set(entry.hash, entry);

nexts.forEach(function (e) {
return _this3._nextsIndex[e] = entry.hash;
});
Expand Down Expand Up @@ -603,7 +606,8 @@ function (_GSet) {

Object.values(newItems).forEach(addToNextsIndex); // Update the internal entry index

this._entryIndex = Object.assign(this._entryIndex, newItems); // Merge the heads
this._entryIndex.add(newItems); // Merge the heads


notReferencedByNewItems = function notReferencedByNewItems(e) {
return !nextsFromNewItems.find(function (a) {
Expand All @@ -622,9 +626,10 @@ function (_GSet) {
if (size > -1) {
tmp = this.values;
tmp = tmp.slice(-size);
this._entryIndex = tmp.reduce(uniqueEntriesReducer, {});
this._entryIndex = null;
this._entryIndex = new EntryIndex(tmp.reduce(uniqueEntriesReducer, {}));
this._headsIndex = Log.findHeads(tmp).reduce(uniqueEntriesReducer, {});
this._length = Object.values(this._entryIndex).length;
this._length = this._entryIndex.length;
} // Find the latest clock from the heads


Expand Down
Loading