reduce unnecessary database connections
parent
1d434264f6
commit
42dba58325
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue