mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
dispatchUpdateInstalledApps without upsert at mysql
This commit is contained in:
@@ -25,24 +25,58 @@ export async function dispatchUpdateInstalledApps ({ deviceId, action, cache }:
|
|||||||
action: UpdateInstalledAppsAction
|
action: UpdateInstalledAppsAction
|
||||||
cache: Cache
|
cache: Cache
|
||||||
}) {
|
}) {
|
||||||
|
async function upsert({ type, data }: { type: number, data: Buffer }) {
|
||||||
|
const dialect = cache.database.dialect
|
||||||
|
const isMysql = dialect === 'mysql' || dialect === 'mariadb'
|
||||||
|
|
||||||
|
if (isMysql) {
|
||||||
|
const counter = await cache.database.encryptedAppList.count({
|
||||||
|
where: {
|
||||||
|
familyId: cache.familyId,
|
||||||
|
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) {
|
||||||
await cache.database.encryptedAppList.upsert({
|
await upsert({ type: types.base, data: action.base })
|
||||||
familyId: cache.familyId,
|
|
||||||
deviceId,
|
|
||||||
type: types.base,
|
|
||||||
version: generateVersionId(),
|
|
||||||
data: action.base
|
|
||||||
}, { transaction: cache.transaction })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.diff) {
|
if (action.diff) {
|
||||||
await cache.database.encryptedAppList.upsert({
|
await upsert({ type: types.diff, data: action.diff })
|
||||||
familyId: cache.familyId,
|
|
||||||
deviceId,
|
|
||||||
type: types.diff,
|
|
||||||
version: generateVersionId(),
|
|
||||||
data: action.diff
|
|
||||||
}, { transaction: cache.transaction })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.wipe) {
|
if (action.wipe) {
|
||||||
|
|||||||
Reference in New Issue
Block a user