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:
* Alerts box should not be clickable, bar should be.
* Issue page: Captcha.
* Enable text search for `locationName` on find-code page.
* Responsive text sizes for boards.

View File

@ -78,10 +78,19 @@ async function query(collection, query){
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 = {
putCorpus,
putStations,
dropCollection,
updateMeta,
query
query,
ensureIndex
}

View File

@ -12,7 +12,7 @@ async function init(){
var status = await check('corpus');
if (status == "not_ready") {
try {
build("corpus")
await build("corpus")
} catch (err) {
log.out("dbInitUtils.init: Error building corpus database")
log.out(err)
@ -22,12 +22,13 @@ async function init(){
var status = await check('stations')
if (status == "not_ready") {
try {
build("stations")
await build("stations")
} catch (err) {
log.out("dbInitUtils.init: Error building stations database")
log.out(err)
}
}
indexes();
}
async function check(coll){
@ -61,7 +62,7 @@ async function build(db){ // `db` must be one of: `corpus`, `stations`, `all`.
await dbAccess.dropCollection("corpus");
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()));
}
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);
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()));
}
}
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 = {
init
}