mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2025-10-06 03:50:05 +02:00
Chunk big or-clause when updating app activities
This commit is contained in:
parent
1969fe4042
commit
4c6f1c0b9e
1 changed files with 39 additions and 26 deletions
|
@ -15,6 +15,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { chunk } from 'lodash'
|
||||||
import * as Sequelize from 'sequelize'
|
import * as Sequelize from 'sequelize'
|
||||||
import { UpdateAppActivitiesAction } from '../../../../action'
|
import { UpdateAppActivitiesAction } from '../../../../action'
|
||||||
import { AppActivityAttributes } from '../../../../database/appactivity'
|
import { AppActivityAttributes } from '../../../../database/appactivity'
|
||||||
|
@ -26,12 +27,17 @@ export async function dispatchUpdateAppActivities ({ deviceId, action, cache }:
|
||||||
cache: Cache
|
cache: Cache
|
||||||
}) {
|
}) {
|
||||||
if (action.updatedOrAdded.length > 0) {
|
if (action.updatedOrAdded.length > 0) {
|
||||||
|
const chuncks = chunk(action.updatedOrAdded, 500)
|
||||||
|
|
||||||
|
for (let i = 0; i < chuncks.length; i++) {
|
||||||
|
const items = chuncks[i]
|
||||||
|
|
||||||
await cache.database.appActivity.destroy({
|
await cache.database.appActivity.destroy({
|
||||||
where: {
|
where: {
|
||||||
familyId: cache.familyId,
|
familyId: cache.familyId,
|
||||||
deviceId,
|
deviceId,
|
||||||
[Sequelize.Op.or]: (
|
[Sequelize.Op.or]: (
|
||||||
action.updatedOrAdded.map((item) => ({
|
items.map((item) => ({
|
||||||
packageName: item.packageName,
|
packageName: item.packageName,
|
||||||
activityName: item.activityName
|
activityName: item.activityName
|
||||||
}))
|
}))
|
||||||
|
@ -39,6 +45,7 @@ export async function dispatchUpdateAppActivities ({ deviceId, action, cache }:
|
||||||
},
|
},
|
||||||
transaction: cache.transaction
|
transaction: cache.transaction
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
await cache.database.appActivity.bulkCreate(
|
await cache.database.appActivity.bulkCreate(
|
||||||
action.updatedOrAdded.map((item): AppActivityAttributes => ({
|
action.updatedOrAdded.map((item): AppActivityAttributes => ({
|
||||||
|
@ -53,12 +60,17 @@ export async function dispatchUpdateAppActivities ({ deviceId, action, cache }:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.removed.length > 0) {
|
if (action.removed.length > 0) {
|
||||||
|
const chunks = chunk(action.removed, 500)
|
||||||
|
|
||||||
|
for (let i = 0; i < chunks.length; i++) {
|
||||||
|
const items = chunks[i]
|
||||||
|
|
||||||
await cache.database.appActivity.destroy({
|
await cache.database.appActivity.destroy({
|
||||||
where: {
|
where: {
|
||||||
familyId: cache.familyId,
|
familyId: cache.familyId,
|
||||||
deviceId,
|
deviceId,
|
||||||
[Sequelize.Op.or]: (
|
[Sequelize.Op.or]: (
|
||||||
action.removed.map((item) => ({
|
items.map((item) => ({
|
||||||
packageName: item.packageName,
|
packageName: item.packageName,
|
||||||
activityName: item.activityName
|
activityName: item.activityName
|
||||||
}))
|
}))
|
||||||
|
@ -67,6 +79,7 @@ export async function dispatchUpdateAppActivities ({ deviceId, action, cache }:
|
||||||
transaction: cache.transaction
|
transaction: cache.transaction
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cache.devicesWithModifiedInstalledApps.push(deviceId)
|
cache.devicesWithModifiedInstalledApps.push(deviceId)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue