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.database.start()
.then((db) => {
seer.note('process db');
this.resetPage();
this.updateQuery();
this.database.start();
seer.note('process db');
this.load();
}
seer.note('prep query');
return this.database.filter(db, this.queryCur);
})
.then((filtered) => {
seer.note('filter db');
return this.grid.buildAllArticles(filtered);
})
.then((html) => {
this.load = function()
{
this.resetPage();
this.updateQuery();
seer.note('prep query');
let filtered = this.database.filter(this.queryCur);
seer.note('filter db');
this.grid.buildAllArticles(filtered)
.then((html) =>
{
seer.note('build html');
let stats = this.database.stats();
@ -89,57 +91,10 @@ function Main()
seer.note('render stats');
this.grid.newDisplay(html);
// seer.note('render html');
seer.report();
document.querySelector('.loading-wave').style.display = 'none';
})
.catch((error) => {
console.log('ERROR:', error);
})
// this.load(window.document.location.hash);
//
});
document.querySelector('.loading-wave').style.display = 'none';
}
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.quota = 0;
this.limbo = false;
this.timeBegin = null;
this.timeRef = null;
@ -12,13 +13,24 @@ function Seer()
{
this.verbose = verbose;
this.quota = quota;
this.timeBegin = Date.now();
this.rebirth();
}
this.rebirth = function()
{
this.timeBegin = Date.now();
this.timeRef = Date.now();
this.book = [];
this.limbo = false;
}
this.note = function(desc)
{
if (this.limbo)
{
this.rebirth();
}
var entry = [desc, (Date.now() - this.timeRef)];
this.book.push(entry);
if (this.verbose)
@ -44,5 +56,7 @@ function Seer()
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()
{
let data = this.database;
return new Promise(function(resolve, reject)
let keys = Object.keys(this.database);
for (let i = 0; i < keys.length; i++)
{
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 entry = this.database[keys[i]];
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;
}
entry.AUTH = commaSplit(entry.AUTH);
entry.TAGS = commaSplit(entry.TAGS);
entry.TYPE = commaSplit(entry.TYPE);
entry.PROJ = commaSplit(entry.PROJ);
let keys = Object.keys(data);
for (let i = 0; i < keys.length; i++)
{
let entry = data[keys[i]];
entry.LINK = objectSplit(entry.LINK);
entry.FILE = objectSplit(entry.FILE);
entry.AUTH = commaSplit(entry.AUTH);
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.database[keys[i]].DIID = i;
}
}
this.filter = function(db, target)
this.filter = function(target, data)
{
let db = this.database;//data == undefined ? this.database : data;
let tempDatabase = {};
if (target == '')
{
@ -192,6 +159,35 @@ function Wrap()
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)
{
// CALCULATE