mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-23 05:39:05 +00:00
feat: wrap upload db insert within transaction
This commit is contained in:
parent
d8b78d29ed
commit
edf7c091e4
@ -1059,17 +1059,20 @@ self.storeFilesToDb = async (req, res, filesData) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert new files to DB
|
await utils.db.transaction(async trx => {
|
||||||
await utils.db.table('files').insert(files)
|
// Insert new files to DB
|
||||||
utils.invalidateStatsCache('uploads')
|
await trx('files')
|
||||||
|
.insert(files)
|
||||||
|
utils.invalidateStatsCache('uploads')
|
||||||
|
|
||||||
// Update albums' timestamp
|
// Update albums' timestamp
|
||||||
if (authorizedIds.length) {
|
if (authorizedIds.length) {
|
||||||
await utils.db.table('albums')
|
await trx('albums')
|
||||||
.whereIn('id', authorizedIds)
|
.whereIn('id', authorizedIds)
|
||||||
.update('editedAt', Math.floor(Date.now() / 1000))
|
.update('editedAt', Math.floor(Date.now() / 1000))
|
||||||
utils.deleteStoredAlbumRenders(authorizedIds)
|
utils.deleteStoredAlbumRenders(authorizedIds)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return [...files, ...exists]
|
return [...files, ...exists]
|
||||||
|
Loading…
Reference in New Issue
Block a user