mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2025-10-03 09:49:32 +02:00
Use upsert for the app list with mysql
This commit is contained in:
parent
d808661ebe
commit
1414e41672
1 changed files with 7 additions and 43 deletions
|
@ -26,49 +26,13 @@ export async function dispatchUpdateInstalledApps ({ deviceId, action, cache }:
|
||||||
cache: Cache
|
cache: Cache
|
||||||
}) {
|
}) {
|
||||||
async function upsert({ type, data }: { type: number, data: Buffer }) {
|
async function upsert({ type, data }: { type: number, data: Buffer }) {
|
||||||
const dialect = cache.database.dialect
|
await cache.database.encryptedAppList.upsert({
|
||||||
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
|
familyId: cache.familyId,
|
||||||
|
deviceId,
|
||||||
if (isMysql) {
|
type,
|
||||||
const counter = await cache.database.encryptedAppList.count({
|
version: generateVersionId(),
|
||||||
where: {
|
data
|
||||||
familyId: cache.familyId,
|
}, { transaction: cache.transaction })
|
||||||
deviceId,
|
|
||||||
type
|
|
||||||
},
|
|
||||||
transaction: cache.transaction
|
|
||||||
})
|
|
||||||
|
|
||||||
if (counter === 0) {
|
|
||||||
await cache.database.encryptedAppList.create({
|
|
||||||
familyId: cache.familyId,
|
|
||||||
deviceId,
|
|
||||||
type,
|
|
||||||
version: generateVersionId(),
|
|
||||||
data
|
|
||||||
}, { transaction: cache.transaction })
|
|
||||||
} else {
|
|
||||||
await cache.database.encryptedAppList.update({
|
|
||||||
data,
|
|
||||||
version: generateVersionId()
|
|
||||||
}, {
|
|
||||||
where: {
|
|
||||||
familyId: cache.familyId,
|
|
||||||
deviceId,
|
|
||||||
type
|
|
||||||
},
|
|
||||||
transaction: cache.transaction
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await cache.database.encryptedAppList.upsert({
|
|
||||||
familyId: cache.familyId,
|
|
||||||
deviceId,
|
|
||||||
type,
|
|
||||||
version: generateVersionId(),
|
|
||||||
data
|
|
||||||
}, { transaction: cache.transaction })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.base) {
|
if (action.base) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue