mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Use upsert for the app list with mysql
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user