Skip to content

Commit

Permalink
Initial refactoring of createIndexes() for very large data sets (40…
Browse files Browse the repository at this point in the history
…MB+) [WIP]
  • Loading branch information
avoidwork committed Sep 30, 2015
1 parent 06a62d8 commit 880cbce
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
22 changes: 16 additions & 6 deletions lib/haro.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright 2015
* @license BSD-3-Clause
* @link http://haro.rocks
* @version 1.7.3
* @version 1.7.4
*/
"use strict";

Expand Down Expand Up @@ -120,15 +120,25 @@ function delIndex (index, indexes, delimiter, key, data, pattern) {
}

function createIndexes (args, indexes, key, delimiter, pattern) {
let result = new Map();
let result = {};

indexes.forEach(function (i) {
result.set(i, new Map());
result[i] = {};
});

args.forEach(function (i) {
if (i[key] !== undefined) {
setIndex(indexes, result, delimiter, i[key], i, undefined, pattern);
let lkey = i[key];

if (lkey !== undefined) {
indexes.forEach(function (index) {
let lindex = keyIndex(index, i, delimiter, pattern);

if (result[index][lindex] === undefined) {
result[index][lindex] = [];
}

result[index][lindex].push(lkey);
});
}
});

Expand Down Expand Up @@ -1089,7 +1099,7 @@ function factory (data = null, config = {}, indexes = []) {
}

factory.transform = cast;
factory.version = "1.7.3";
factory.version = "1.7.4";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
22 changes: 16 additions & 6 deletions lib/haro.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright 2015
* @license BSD-3-Clause
* @link http://haro.rocks
* @version 1.7.3
* @version 1.7.4
*/
"use strict";

Expand Down Expand Up @@ -124,15 +124,25 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}

function createIndexes(args, indexes, key, delimiter, pattern) {
var result = new Map();
var result = {};

indexes.forEach(function (i) {
result.set(i, new Map());
result[i] = {};
});

args.forEach(function (i) {
if (i[key] !== undefined) {
setIndex(indexes, result, delimiter, i[key], i, undefined, pattern);
var lkey = i[key];

if (lkey !== undefined) {
indexes.forEach(function (index) {
var lindex = keyIndex(index, i, delimiter, pattern);

if (result[index][lindex] === undefined) {
result[index][lindex] = [];
}

result[index][lindex].push(lkey);
});
}
});

Expand Down Expand Up @@ -1221,7 +1231,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}

factory.transform = cast;
factory.version = "1.7.3";
factory.version = "1.7.4";

// Node, AMD & window supported
if (typeof exports !== "undefined") {
Expand Down
2 changes: 1 addition & 1 deletion lib/haro.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/haro.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haro",
"version": "1.7.3",
"version": "1.7.4",
"description": "Harō is a modern immutable DataStore using Maps, Sets, Promises, & Tuples",
"main": "lib/haro.js",
"scripts": {
Expand Down
18 changes: 14 additions & 4 deletions src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,25 @@ function delIndex (index, indexes, delimiter, key, data, pattern) {
}

function createIndexes (args, indexes, key, delimiter, pattern) {
let result = new Map();
let result = {};

indexes.forEach(function (i) {
result.set(i, new Map());
result[i] = {};
});

args.forEach(function (i) {
if (i[key] !== undefined) {
setIndex(indexes, result, delimiter, i[key], i, undefined, pattern);
let lkey = i[key];

if (lkey !== undefined) {
indexes.forEach(function (index) {
let lindex = keyIndex(index, i, delimiter, pattern);

if (result[index][lindex] === undefined) {
result[index][lindex] = [];
}

result[index][lindex].push(lkey);
});
}
});

Expand Down
2 changes: 2 additions & 0 deletions test/haro_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,13 @@ exports["offload (indexes)"] = {

test.expect(3);
this.store.offload(data).then(function (args) {
console.log(args);
test.equal(Object.keys(args).length, self.store.index.length, "Should be a match");
test.equal(Object.keys(args.name).length, 6, "Should be '6'");
test.equal(args.age['20'].length, 2, "Should be '2'");
test.done();
}, function (e) {
console.log(e);
throw e;
test.done();
});
Expand Down

0 comments on commit 880cbce

Please sign in to comment.