mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2025-10-03 01:39:31 +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,41 +26,6 @@ export async function dispatchUpdateInstalledApps ({ deviceId, action, 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,
|
||||
|
@ -69,7 +34,6 @@ export async function dispatchUpdateInstalledApps ({ deviceId, action, cache }:
|
|||
data
|
||||
}, { transaction: cache.transaction })
|
||||
}
|
||||
}
|
||||
|
||||
if (action.base) {
|
||||
await upsert({ type: types.base, data: action.base })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue