Add load (links working again) with new promise setup. Improve seer (benchmark).

This commit is contained in:
kor 2018-11-07 00:45:52 +13:00
parent 03b9e3f777
commit 55a9014be2
3 changed files with 76 additions and 111 deletions

View File

@ -65,21 +65,23 @@ function Main()
this.start = function() this.start = function()
{ {
this.database.start() this.database.start();
.then((db) => { seer.note('process db');
seer.note('process db'); this.load();
}
this.resetPage();
this.updateQuery();
seer.note('prep query'); this.load = function()
return this.database.filter(db, this.queryCur); {
}) this.resetPage();
.then((filtered) => { this.updateQuery();
seer.note('filter db'); seer.note('prep query');
return this.grid.buildAllArticles(filtered);
}) let filtered = this.database.filter(this.queryCur);
.then((html) => { seer.note('filter db');
this.grid.buildAllArticles(filtered)
.then((html) =>
{
seer.note('build html'); seer.note('build html');
let stats = this.database.stats(); let stats = this.database.stats();
@ -89,57 +91,10 @@ function Main()
seer.note('render stats'); seer.note('render stats');
this.grid.newDisplay(html); this.grid.newDisplay(html);
// seer.note('render html');
seer.report(); seer.report();
});
document.querySelector('.loading-wave').style.display = 'none'; document.querySelector('.loading-wave').style.display = 'none';
})
.catch((error) => {
console.log('ERROR:', error);
})
// this.load(window.document.location.hash);
//
} }
this.load = function()
{
}
// this.load = function(target)
// {
// lightbox.close();
// document.activeElement.blur();
// if (this.queryCur !== 'add')
// {
// this.queryPrev = this.queryCur;
// }
// target = target.substr(0,1) === "#" ? target.substr(1,target.length-1) : target;
// this.queryCur = target.trim();
// if (window.location.hash != this.queryCur)
// {
// window.location.hash = this.queryCur;
// }
// if (this.queryCur === 'add')
// {
// if (window.showAdd != undefined && window.showAdd)
// {
// this.add.show();
// }
// else
// {
// window.location.hash = this.queryPrev;
// }
// }
// else
// {
// this.grid.display(this.db.filter(this.queryCur));
// }
// }
} }
// window.addEventListener("hashchange", function() { main.load(window.document.location.hash); }); window.addEventListener("hashchange", function() { main.load(); });

View File

@ -3,6 +3,7 @@ function Seer()
{ {
this.verbose = false this.verbose = false
this.quota = 0; this.quota = 0;
this.limbo = false;
this.timeBegin = null; this.timeBegin = null;
this.timeRef = null; this.timeRef = null;
@ -12,13 +13,24 @@ function Seer()
{ {
this.verbose = verbose; this.verbose = verbose;
this.quota = quota; this.quota = quota;
this.timeBegin = Date.now(); this.rebirth();
}
this.rebirth = function()
{
this.timeBegin = Date.now();
this.timeRef = Date.now(); this.timeRef = Date.now();
this.book = []; this.book = [];
this.limbo = false;
} }
this.note = function(desc) this.note = function(desc)
{ {
if (this.limbo)
{
this.rebirth();
}
var entry = [desc, (Date.now() - this.timeRef)]; var entry = [desc, (Date.now() - this.timeRef)];
this.book.push(entry); this.book.push(entry);
if (this.verbose) if (this.verbose)
@ -44,5 +56,7 @@ function Seer()
console.log(percentage + ' % of time spent on: ' + this.book[i][0]); console.log(percentage + ' % of time spent on: ' + this.book[i][0]);
} }
} }
console.log('_____________________________');
this.limbo = true;
} }
} }

View File

@ -11,59 +11,26 @@ function Wrap()
this.start = function() this.start = function()
{ {
let data = this.database; let keys = Object.keys(this.database);
return new Promise(function(resolve, reject) for (let i = 0; i < keys.length; i++)
{ {
let commaSplit = function(data) let entry = this.database[keys[i]];
{
if (data !== undefined)
{
var result = data.split(",");
for (var c = 0; c < result.length; c++)
{
result[c] = result[c].trim().toLowerCase();
}
return result;
}
return data;
}
let objectSplit = function(data) entry.AUTH = commaSplit(entry.AUTH);
{ entry.TAGS = commaSplit(entry.TAGS);
if (typeof data == 'object') entry.TYPE = commaSplit(entry.TYPE);
{ entry.PROJ = commaSplit(entry.PROJ);
for (let o = 0; o < data.length; o++)
{
if (data[o].substr(0,2) == '> ')
{
data[o] = data[o].substr(2,data[o].length-1);
}
}
}
return data;
}
let keys = Object.keys(data); entry.LINK = objectSplit(entry.LINK);
for (let i = 0; i < keys.length; i++) entry.FILE = objectSplit(entry.FILE);
{
let entry = data[keys[i]];
entry.AUTH = commaSplit(entry.AUTH); this.database[keys[i]].DIID = i;
entry.TAGS = commaSplit(entry.TAGS); }
entry.TYPE = commaSplit(entry.TYPE);
entry.PROJ = commaSplit(entry.PROJ);
entry.LINK = objectSplit(entry.LINK);
entry.FILE = objectSplit(entry.FILE);
data[keys[i]].DIID = i;
}
resolve(data);
});
} }
this.filter = function(db, target) this.filter = function(target, data)
{ {
let db = this.database;//data == undefined ? this.database : data;
let tempDatabase = {}; let tempDatabase = {};
if (target == '') if (target == '')
{ {
@ -192,6 +159,35 @@ function Wrap()
return tempDatabase; return tempDatabase;
} }
let commaSplit = function(data)
{
if (data !== undefined)
{
var result = data.split(",");
for (var c = 0; c < result.length; c++)
{
result[c] = result[c].trim().toLowerCase();
}
return result;
}
return data;
}
let objectSplit = function(data)
{
if (typeof data == 'object')
{
for (let o = 0; o < data.length; o++)
{
if (data[o].substr(0,2) == '> ')
{
data[o] = data[o].substr(2,data[o].length-1);
}
}
}
return data;
}
this.stats = function(db = this.database) this.stats = function(db = this.database)
{ {
// CALCULATE // CALCULATE