Backend: Add DB Indexes

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-02-02 12:25:26 +00:00
parent 5223f5298a
commit d381f85ad0
3 changed files with 23 additions and 6 deletions

View File

@ -3,7 +3,6 @@
## Frontend: ## Frontend:
* Alerts box should not be clickable, bar should be. * Alerts box should not be clickable, bar should be.
* Issue page: Captcha.
* Enable text search for `locationName` on find-code page. * Enable text search for `locationName` on find-code page.
* Responsive text sizes for boards. * Responsive text sizes for boards.

View File

@ -78,10 +78,19 @@ async function query(collection, query){
return (await qcursor.toArray()); return (await qcursor.toArray());
} }
async function ensureIndex(col, field) {
await client.connect();
log.out(`dbAccess.ensureIndex: Creating index in collection ${col} for field ${field}`)
let res = await db.createIndex(col, field);
log.out(`dbAccess.ensureIndex: Index created`);
return;
}
module.exports = { module.exports = {
putCorpus, putCorpus,
putStations, putStations,
dropCollection, dropCollection,
updateMeta, updateMeta,
query query,
ensureIndex
} }

View File

@ -12,7 +12,7 @@ async function init(){
var status = await check('corpus'); var status = await check('corpus');
if (status == "not_ready") { if (status == "not_ready") {
try { try {
build("corpus") await build("corpus")
} catch (err) { } catch (err) {
log.out("dbInitUtils.init: Error building corpus database") log.out("dbInitUtils.init: Error building corpus database")
log.out(err) log.out(err)
@ -22,12 +22,13 @@ async function init(){
var status = await check('stations') var status = await check('stations')
if (status == "not_ready") { if (status == "not_ready") {
try { try {
build("stations") await build("stations")
} catch (err) { } catch (err) {
log.out("dbInitUtils.init: Error building stations database") log.out("dbInitUtils.init: Error building stations database")
log.out(err) log.out(err)
} }
} }
indexes();
} }
async function check(coll){ async function check(coll){
@ -61,7 +62,7 @@ async function build(db){ // `db` must be one of: `corpus`, `stations`, `all`.
await dbAccess.dropCollection("corpus"); await dbAccess.dropCollection("corpus");
dbAccess.putCorpus(corpusAll); dbAccess.putCorpus(corpusAll);
log.out(`dbInitUtils.build: Updating corpus meta`) log.out(`dbInitUtils.build: Updating corpus meta`);
dbAccess.updateMeta("collection", "corpus", time.jsUnix(Date.now())); dbAccess.updateMeta("collection", "corpus", time.jsUnix(Date.now()));
} }
if (db === "stations") { if (db === "stations") {
@ -69,11 +70,19 @@ async function build(db){ // `db` must be one of: `corpus`, `stations`, `all`.
var corpusSubset = await corpus.subset(corpusAll); var corpusSubset = await corpus.subset(corpusAll);
dbAccess.putStations(corpusSubset); dbAccess.putStations(corpusSubset);
log.out(`dbInitUtils.build: Updating stations meta`) log.out(`dbInitUtils.build: Updating stations meta`);
dbAccess.updateMeta("collection", "stations", time.jsUnix(Date.now())); dbAccess.updateMeta("collection", "stations", time.jsUnix(Date.now()));
} }
} }
async function indexes() {
dbAccess.ensureIndex("corpus", "NLC");
dbAccess.ensureIndex("corpus", "3ALPHA");
dbAccess.ensureIndex("stations", "3ALPHA");
dbAccess.ensureIndex("stations", "STANOX");
dbAccess.ensureIndex("stations", "TIPLOC");
}
module.exports = { module.exports = {
init init
} }