Browse Source

optimize #2011: Added indices to the login and character tables for assisting in case insensitive checks

tags/v0.14.0^2
Shaun 4 months ago
parent
commit
4ec2d17a84
2 changed files with 14 additions and 26 deletions
  1. +0
    -25
      src/server/components/auth.js
  2. +14
    -1
      src/server/db/ioRethink.js

+ 0
- 25
src/server/components/auth.js View File

@@ -425,7 +425,6 @@ module.exports = {
msg.callback(); msg.callback();
}, },


/* eslint-disable-next-line max-lines-per-function */
createCharacter: async function (msg) { createCharacter: async function (msg) {
let data = msg.data; let data = msg.data;
let name = data.name; let name = data.name;
@@ -459,14 +458,8 @@ module.exports = {
return; return;
} }


console.log('Starting new character create for', name);
const t1 = +new Date();

const releaseCreateLock = await getCreateLock(); const releaseCreateLock = await getCreateLock();


const t2 = +new Date();
console.log('Took', t2 - t1, 'ms to get a create lock');

let exists = await io.getAsync({ let exists = await io.getAsync({
key: name, key: name,
ignoreCase: true, ignoreCase: true,
@@ -474,9 +467,6 @@ module.exports = {
noDefault: true noDefault: true
}); });


const t3 = +new Date();
console.log('Took', t3 - t2, 'ms to check if the character exists');

if (exists) { if (exists) {
releaseCreateLock(); releaseCreateLock();
msg.callback(messages.login.charExists); msg.callback(messages.login.charExists);
@@ -498,13 +488,7 @@ module.exports = {


let simple = this.obj.getSimple(true); let simple = this.obj.getSimple(true);


const t4 = +new Date();
console.log('Took', t4 - t3, 'ms to build the simpleObj');

await this.verifySkin(simple); await this.verifySkin(simple);

const t5 = +new Date();
console.log('Took', t5 - t4, 'ms to verify the skin');
let prophecies = (data.prophecies || []).filter(p => p); let prophecies = (data.prophecies || []).filter(p => p);
@@ -523,9 +507,6 @@ module.exports = {


eventEmitter.emit('beforeSaveCharacter', eBeforeSaveCharacter); eventEmitter.emit('beforeSaveCharacter', eBeforeSaveCharacter);


const t6 = +new Date();
console.log('Took', t6 - t5, 'ms to run beforeSaveCharacter');

await io.setAsync({ await io.setAsync({
key: name, key: name,
table: 'character', table: 'character',
@@ -535,9 +516,6 @@ module.exports = {


this.characters[name] = simple; this.characters[name] = simple;
this.characterList.push(name); this.characterList.push(name);

const t7 = +new Date();
console.log('Took', t7 - t6, 'ms to save the character');
await io.setAsync({ await io.setAsync({
key: this.username, key: this.username,
@@ -546,9 +524,6 @@ module.exports = {
serialize: true serialize: true
}); });


const t8 = +new Date();
console.log('Took', t8 - t7, 'ms to save the character list');

releaseCreateLock(); releaseCreateLock();


this.initTracker(); this.initTracker();


+ 14
- 1
src/server/db/ioRethink.js View File

@@ -33,6 +33,19 @@ module.exports = {
_.log(e); _.log(e);
} }
} }

//Create indices used for case-insensitive checks
if (!(await r.table('login').indexList()).includes('idLowerCase')) {
await r.table('login').indexCreate('idLowerCase', r.row('id').downcase());

_.log('Created index: idLowerCase on table: login');
}

if (!(await r.table('character').indexList()).includes('idLowerCase')) {
await r.table('character').indexCreate('idLowerCase', r.row('id').downcase());

_.log('Created index: idLowerCase on table: character');
}
}, },


createTable: async function (tableName) { createTable: async function (tableName) {
@@ -46,7 +59,7 @@ module.exports = {


getAsyncIgnoreCase: async function (table, key) { getAsyncIgnoreCase: async function (table, key) {
const res = await r.table(table) const res = await r.table(table)
.filter(doc => doc('id').match(`(?i)^${key}$`))
.getAll(key.toLowerCase(), { index: 'idLowerCase' })
.run(); .run();


return res[0]; return res[0];


Loading…
Cancel
Save