track used search terms to reduce slow downs
parent
816ea77749
commit
9fa374d8c5
|
|
@ -15,13 +15,14 @@ export function getLotNameWhereClause(lotName = '', lotNameSearchType, lotsTable
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
const usedPieces = new Set();
|
||||||
const lotNamePieces = lotName.toLowerCase().split(' ');
|
const lotNamePieces = lotName.toLowerCase().split(' ');
|
||||||
for (const lotNamePiece of lotNamePieces) {
|
for (const lotNamePiece of lotNamePieces) {
|
||||||
if (lotNamePiece === '') {
|
if (lotNamePiece === '' || usedPieces.has(lotNamePiece)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sqlWhereClause +=
|
usedPieces.add(lotNamePiece);
|
||||||
' and instr(lower(' + lotsTableAlias + '.lotName), ?)';
|
sqlWhereClause += ` and instr(lower(${lotsTableAlias}.lotName), ?)`;
|
||||||
sqlParameters.push(lotNamePiece);
|
sqlParameters.push(lotNamePiece);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,15 +71,15 @@ export function getOccupancyTimeWhereClause(occupancyTime, lotOccupanciesTableAl
|
||||||
export function getOccupantNameWhereClause(occupantName = '', tableAlias = 'o') {
|
export function getOccupantNameWhereClause(occupantName = '', tableAlias = 'o') {
|
||||||
let sqlWhereClause = '';
|
let sqlWhereClause = '';
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if (occupantName !== '') {
|
const usedPieces = new Set();
|
||||||
const occupantNamePieces = occupantName.toLowerCase().split(' ');
|
const occupantNamePieces = occupantName.toLowerCase().split(' ');
|
||||||
for (const occupantNamePiece of occupantNamePieces) {
|
for (const occupantNamePiece of occupantNamePieces) {
|
||||||
if (occupantNamePiece === '') {
|
if (occupantNamePiece === '' || usedPieces.has(occupantNamePiece)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
sqlWhereClause += ` and (instr(lower(${tableAlias}.occupantName), ?) or instr(lower(${tableAlias}.occupantFamilyName), ?))`;
|
|
||||||
sqlParameters.push(occupantNamePiece, occupantNamePiece);
|
|
||||||
}
|
}
|
||||||
|
usedPieces.add(occupantNamePiece);
|
||||||
|
sqlWhereClause += ` and (instr(lower(${tableAlias}.occupantName), ?) or instr(lower(${tableAlias}.occupantFamilyName), ?))`;
|
||||||
|
sqlParameters.push(occupantNamePiece, occupantNamePiece);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,18 @@ export function getLotNameWhereClause(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
const usedPieces = new Set<string>()
|
||||||
|
|
||||||
const lotNamePieces = lotName.toLowerCase().split(' ')
|
const lotNamePieces = lotName.toLowerCase().split(' ')
|
||||||
|
|
||||||
for (const lotNamePiece of lotNamePieces) {
|
for (const lotNamePiece of lotNamePieces) {
|
||||||
if (lotNamePiece === '') {
|
if (lotNamePiece === '' || usedPieces.has(lotNamePiece)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlWhereClause +=
|
usedPieces.add(lotNamePiece)
|
||||||
' and instr(lower(' + lotsTableAlias + '.lotName), ?)'
|
|
||||||
|
sqlWhereClause += ` and instr(lower(${lotsTableAlias}.lotName), ?)`
|
||||||
sqlParameters.push(lotNamePiece)
|
sqlParameters.push(lotNamePiece)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,16 +105,18 @@ export function getOccupantNameWhereClause(
|
||||||
let sqlWhereClause = ''
|
let sqlWhereClause = ''
|
||||||
const sqlParameters: unknown[] = []
|
const sqlParameters: unknown[] = []
|
||||||
|
|
||||||
if (occupantName !== '') {
|
const usedPieces = new Set<string>()
|
||||||
const occupantNamePieces = occupantName.toLowerCase().split(' ')
|
|
||||||
for (const occupantNamePiece of occupantNamePieces) {
|
|
||||||
if (occupantNamePiece === '') {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlWhereClause += ` and (instr(lower(${tableAlias}.occupantName), ?) or instr(lower(${tableAlias}.occupantFamilyName), ?))`
|
const occupantNamePieces = occupantName.toLowerCase().split(' ')
|
||||||
sqlParameters.push(occupantNamePiece, occupantNamePiece)
|
for (const occupantNamePiece of occupantNamePieces) {
|
||||||
|
if (occupantNamePiece === '' || usedPieces.has(occupantNamePiece)) {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usedPieces.add(occupantNamePiece)
|
||||||
|
|
||||||
|
sqlWhereClause += ` and (instr(lower(${tableAlias}.occupantName), ?) or instr(lower(${tableAlias}.occupantFamilyName), ?))`
|
||||||
|
sqlParameters.push(occupantNamePiece, occupantNamePiece)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue