Skip to content

Commit 5767651

Browse files
author
Peter Hasitschka
committed
saving localstorage through truncating descriptions
1 parent 3536077 commit 5767651

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

Dashboard/js/querydb.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,34 @@ var QueryResultDb = function () {
1616

1717
/**
1818
* Store data that was sent by catching a window message in starter.js
19-
* @param {type} data Event.data object
19+
* @param {type} obj Event.data object
2020
*/
21-
QueryResultDb.prototype.saveQueryResults = function (data) {
21+
QueryResultDb.prototype.saveQueryResults = function (obj) {
2222

23-
console.log("Saving new query results", data);
23+
/**
24+
* Removing description-data of the results due to large data
25+
*/
26+
var remove_description = false;
2427

25-
if (!data.data)
28+
if (remove_description && obj.data && obj.data.result) {
29+
30+
for (var i = 0; i < obj.data.result.length; i++) {
31+
32+
var res = obj.data.result[i];
33+
34+
if (res.description !== undefined) {
35+
res.description = "TRUNCATED AT SAVING TO LOCALSTORAGE";
36+
}
37+
38+
if (res.v2DataItem !== undefined && res.v2DataItem.description !== undefined) {
39+
res.v2DataItem.description = "TRUNCATED AT SAVING TO LOCALSTORAGE";
40+
}
41+
}
42+
}
43+
44+
console.log("Saving new query results", obj);
45+
46+
if (!obj.data)
2647
return;
2748

2849

@@ -32,14 +53,17 @@ QueryResultDb.prototype.saveQueryResults = function (data) {
3253
throw ("Could not get a free key for storing the query-data in local storage");
3354

3455

35-
data.data.id = key;
36-
var value = JSON.stringify(data.data);
56+
obj.data.id = key;
3757

58+
var value = JSON.stringify(obj.data);
59+
60+
console.log("Saving new query with length " + value.length);
61+
3862
if (this.compress)
3963
value = LZString.compress(value);
4064

41-
42-
this.forceStoring(this.prefix + key, value)
65+
66+
this.forceStoring(this.prefix + key, value);
4367

4468
};
4569

@@ -51,20 +75,20 @@ QueryResultDb.prototype.saveQueryResults = function (data) {
5175
* @param {type} key
5276
* @param {type} val
5377
*/
54-
QueryResultDb.prototype.forceStoring = function(key,val){
78+
QueryResultDb.prototype.forceStoring = function (key, val) {
5579
try {
5680
//console.log("Storing a query with key " + key);
5781
localStorage.setItem(key, val);
5882

5983
} catch (QuotaExceededError) {
60-
84+
6185
var key_to_delete = this.getOldestKey();
6286
console.log("Oops. Storage full. Deleting value '" + this.prefix + key_to_delete + "'");
6387

6488
if (key_to_delete === null) {
6589
throw ("Can't get a key for deleting an old query from local storage!");
6690
}
67-
91+
6892
delete localStorage[this.prefix + key_to_delete];
6993
this.forceStoring(key, val);
7094
//delete localStorage[this.prefix + key_to_delete];

WebGlVisualization

0 commit comments

Comments
 (0)