reduce unnecessary database connections

deepsource-autofix-76c6eb20
Dan Gowans 2023-01-04 15:37:35 -05:00
parent 1d434264f6
commit 42dba58325
8 changed files with 35 additions and 36 deletions

View File

@ -22,9 +22,9 @@ export function moveLotStatusUp(lotStatusId) {
return result.changes > 0;
}
export function moveLotStatusUpToTop(lotStatusId) {
const database = sqlite(databasePath);
const currentOrderNumber = getLotStatusById(typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId).orderNumber;
if (currentOrderNumber > 0) {
const database = sqlite(databasePath);
database
.prepare("update LotStatuses set orderNumber = -1 where lotStatusId = ?")
.run(lotStatusId);
@ -34,9 +34,9 @@ export function moveLotStatusUpToTop(lotStatusId) {
where recordDelete_timeMillis is null
and orderNumber < ?`)
.run(currentOrderNumber);
}
database.close();
clearLotStatusesCache();
}
return true;
}
export default moveLotStatusUp;

View File

@ -37,13 +37,13 @@ export function moveLotStatusUp(lotStatusId: number | string): boolean {
}
export function moveLotStatusUpToTop(lotStatusId: number | string): boolean {
const database = sqlite(databasePath);
const currentOrderNumber: number = getLotStatusById(
typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId
).orderNumber;
if (currentOrderNumber > 0) {
const database = sqlite(databasePath);
database
.prepare("update LotStatuses set orderNumber = -1 where lotStatusId = ?")
.run(lotStatusId);
@ -56,11 +56,11 @@ export function moveLotStatusUpToTop(lotStatusId: number | string): boolean {
and orderNumber < ?`
)
.run(currentOrderNumber);
}
database.close();
clearLotStatusesCache();
}
return true;
}

View File

@ -22,8 +22,8 @@ export function moveLotTypeUp(lotTypeId) {
}
export function moveLotTypeUpToTop(lotTypeId) {
const currentOrderNumber = getLotTypeById(typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId).orderNumber;
const database = sqlite(databasePath);
if (currentOrderNumber > 0) {
const database = sqlite(databasePath);
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
database
.prepare(`update LotTypes
@ -31,9 +31,9 @@ export function moveLotTypeUpToTop(lotTypeId) {
where recordDelete_timeMillis is null
and orderNumber < ?`)
.run(currentOrderNumber);
}
database.close();
clearLotTypesCache();
}
return true;
}
export default moveLotTypeUp;

View File

@ -40,9 +40,8 @@ export function moveLotTypeUpToTop(lotTypeId: number | string): boolean {
typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId
).orderNumber;
const database = sqlite(databasePath);
if (currentOrderNumber > 0) {
const database = sqlite(databasePath);
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
database
@ -53,11 +52,11 @@ export function moveLotTypeUpToTop(lotTypeId: number | string): boolean {
and orderNumber < ?`
)
.run(currentOrderNumber);
}
database.close();
clearLotTypesCache();
}
return true;
}

View File

@ -22,8 +22,8 @@ export function moveOccupancyTypeUp(occupancyTypeId) {
}
export function moveOccupancyTypeUpToTop(occupancyTypeId) {
const currentOrderNumber = getOccupancyTypeById(typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId).orderNumber;
const database = sqlite(databasePath);
if (currentOrderNumber > 0) {
const database = sqlite(databasePath);
database
.prepare("update OccupancyTypes set orderNumber = -1 where occupancyTypeId = ?")
.run(occupancyTypeId);
@ -33,9 +33,9 @@ export function moveOccupancyTypeUpToTop(occupancyTypeId) {
where recordDelete_timeMillis is null
and orderNumber < ?`)
.run(currentOrderNumber);
}
database.close();
clearOccupancyTypesCache();
}
return true;
}
export default moveOccupancyTypeUp;

View File

@ -40,9 +40,9 @@ export function moveOccupancyTypeUpToTop(occupancyTypeId: number | string): bool
typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId
).orderNumber;
if (currentOrderNumber > 0) {
const database = sqlite(databasePath);
if (currentOrderNumber > 0) {
database
.prepare("update OccupancyTypes set orderNumber = -1 where occupancyTypeId = ?")
.run(occupancyTypeId);
@ -55,11 +55,11 @@ export function moveOccupancyTypeUpToTop(occupancyTypeId: number | string): bool
and orderNumber < ?`
)
.run(currentOrderNumber);
}
database.close();
clearOccupancyTypesCache();
}
return true;
}

View File

@ -22,8 +22,8 @@ export function moveWorkOrderTypeUp(workOrderTypeId) {
}
export function moveWorkOrderTypeUpToTop(workOrderTypeId) {
const currentOrderNumber = getWorkOrderTypeById(typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId).orderNumber;
const database = sqlite(databasePath);
if (currentOrderNumber > 0) {
const database = sqlite(databasePath);
database
.prepare("update WorkOrderTypes set orderNumber = -1 where workOrderTypeId = ?")
.run(workOrderTypeId);
@ -33,9 +33,9 @@ export function moveWorkOrderTypeUpToTop(workOrderTypeId) {
where recordDelete_timeMillis is null
and orderNumber < ?`)
.run(currentOrderNumber);
}
database.close();
clearWorkOrderTypesCache();
}
return true;
}
export default moveWorkOrderTypeUp;

View File

@ -40,9 +40,9 @@ export function moveWorkOrderTypeUpToTop(workOrderTypeId: number | string): bool
typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId
).orderNumber;
if (currentOrderNumber > 0) {
const database = sqlite(databasePath);
if (currentOrderNumber > 0) {
database
.prepare("update WorkOrderTypes set orderNumber = -1 where workOrderTypeId = ?")
.run(workOrderTypeId);
@ -55,11 +55,11 @@ export function moveWorkOrderTypeUpToTop(workOrderTypeId: number | string): bool
and orderNumber < ?`
)
.run(currentOrderNumber);
}
database.close();
clearWorkOrderTypesCache();
}
return true;
}