Commit 87082ec7 authored by preetwinder's avatar preetwinder

Remove unneeded parts

parent 854c1b59
......@@ -41,72 +41,9 @@
this._version = description.version || undefined;
}
function convertToObject(list, key) {
var i, obj = {};
for (i = 0; i < list.length; i += 1) {
obj[list[i][key]] = list[i];
}
return obj;
}
function keyCount(obj) {
return Object.keys(obj).length;
}
function union(list) {
var result, i, j;
if (list.length === 0) {
return [];
}
result = convertToObject(list[0], 'id');
for (i = 1; i < list.length; i += 1) {
for (j = 0; j < list[i].length; j += 1) {
if (result[list[i][j].id]) {
if (keyCount(result[list[i][j].id].doc) <
keyCount(list[i][j].doc)) {
result[list[i][j].id] = list[i][j];
}
} else {
result[list[i][j].id] = list[i][j];
}
}
}
return Object.values(result);
}
function intersect(list) {
var result, temp = {}, i, j;
if (list.length === 0) {
return [];
}
result = convertToObject(list[0], 'id');
for (i = 1; i < list.length; i += 1) {
for (j = 0; j < list[i].length; j += 1) {
if (result[list[i][j].id]) {
if (keyCount(result[list[i][j].id].doc) <
keyCount(list[i][j].doc)) {
temp[list[i][j].id] = list[i][j];
} else {
temp[list[i][j].id] = result[list[i][j].id];
}
}
}
result = temp;
temp = {};
}
return Object.values(result);
}
IndexStorage2.prototype.hasCapacity = function (name) {
var this_storage_capacity_list = ["select",
"list",
"query",
"sort",
"include"];
if (this_storage_capacity_list.indexOf(name) !== -1) {
return true;
}
return (name === 'query') || (name === 'limit') || (name === 'list') ||
this._sub_storage.hasCapacity(name);
};
function handleUpgradeNeeded(evt, index_keys) {
......@@ -117,9 +54,9 @@
keyPath: "id",
autoIncrement: false
});
current_indices = new Set();
} else {
store = evt.target.transaction.objectStore('index-store');
}
current_indices = new Set(store.indexNames);
for (i = 0; i < index_keys.length; i += 1) {
if (!(current_indices.has(index_keys[i]))) {
......@@ -132,6 +69,7 @@
break;
}
}
}
for (i = 0; i < index_keys.length; i += 1) {
if (!(current_indices.has('Index-' + index_keys[i]))) {
store.createIndex('Index-' + index_keys[i],
......@@ -173,11 +111,10 @@
reject("Connection to: " + db_name + " timeout");
};
// request.onblocked = function (evt) {
// console.log("evt", evt);
// request.result.close();
// reject("Connection to: " + db_name + " was blocked");
// };
request.onblocked = function () {
request.result.close();
reject("Connection to: " + db_name + " was blocked");
};
// Create DB if necessary //
request.onupgradeneeded = function (evt) {
......@@ -264,33 +201,7 @@
return doc;
}
IndexStorage2.prototype.forceIncludeDocs = function (result) {
var i, get_list = {}, context = this;
return RSVP.Queue()
.push(function () {
for (i = 0; i < result.length; i += 1) {
if (!(result[i].include)) {
get_list[result[i].id] = context._sub_storage.get(result[i].id);
}
}
return RSVP.hash(get_list);
})
.push(function (get_result) {
var keys;
result = convertToObject(result, 'id');
keys = Object.keys(get_result);
for (i = 0; i < keys.length; i += 1) {
result[keys[i]].doc = get_result[keys[i]];
}
result = Object.values(result);
return result;
})
.push(function () {
return result;
});
};
IndexStorage2.prototype._runQuery = function (index, value) {
IndexStorage2.prototype._runQuery = function (key, value, limit) {
var context = this;
return new RSVP.Queue()
.push(function () {
......@@ -299,7 +210,7 @@
return waitForTransaction(db, ["index-store"], "readonly",
function (tx) {
return waitForIDBRequest(tx.objectStore("index-store")
.index("Index-" + index).getAll(value))
.index("Index-" + key).getAll(value, limit))
.then(function (evt) {
return evt.target.result;
});
......@@ -308,70 +219,28 @@
});
};
IndexStorage2.prototype._processQueryObject = function (object,
include_docs) {
var promise_list = [], context = this, i;
include_docs = include_docs || false;
return RSVP.Queue()
.push(function () {
if (object.type === "simple") {
if ((context._index_keys.indexOf(object.key) === -1)) {
return context._sub_storage.allDocs({
"query": object.key + ":" + object.value,
"include_docs": include_docs
})
.push(function (result) {
if (include_docs) {
result.data.rows.map(function (v) {
v.include = true;
});
}
return result.data.rows;
});
}
return context._runQuery(object.key, object.value);
}
if (object.type === "complex") {
for (i = 0; i < object.query_list.length; i += 1) {
promise_list.push(context
._processQueryObject(object.query_list[i], include_docs));
}
return RSVP.all(promise_list)
.then(function (result) {
if (object.operator === "OR") {
return union(result);
}
if (object.operator === "AND") {
return intersect(result);
}
});
}
})
};
IndexStorage2.prototype.buildQuery = function (options) {
var context = this;
var context = this, query;
if (options.query) {
return this._processQueryObject(parseStringToObject(options.query),
options.include_docs)
.push(function (result) {
if (options.include_docs) {
result = context.forceIncludeDocs(result);
options.select_list = undefined;
} else {
options.select_list = options.select_list || [];
}
return result;
})
query = parseStringToObject(options.query);
if (query.type === 'simple') {
if (context._index_keys.indexOf(query.key) !== -1) {
return context._runQuery(query.key, query.value, options.limit)
.push(function (result) {
return result.map(function (value) {
return {
"id": value.id,
"value": filterDocValues(value.doc, options.select_list)
id: value.id,
value: {}
};
});
});
}
}
}
return context._sub_storage.allDocs(options)
.push(function (result) {
return result.data.rows;
});
};
IndexStorage2.prototype.get = function () {
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment