Add support for more limits

This commit is contained in:
Jonas Lochmann
2020-05-18 02:00:00 +02:00
parent d021497e52
commit ef1b19a01c
79 changed files with 2785 additions and 136 deletions
+36 -3
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -45,7 +45,7 @@ async function deleteOldUsedTimes ({ database }: {
await database.transaction(async (transaction) => {
// get matching categories
const categoriesToCleanUp = await database.usedTime.findAll({
const categoriesToCleanUpOne = await database.usedTime.findAll({
transaction,
where: {
lastUpdate: {
@@ -56,12 +56,33 @@ async function deleteOldUsedTimes ({ database }: {
'familyId',
'categoryId'
],
limit: 100
limit: 1000,
order: [['lastUpdate', 'ASC']]
}).map((item) => ({
familyId: item.familyId,
categoryId: item.categoryId
}))
const categoriesToCleanUpTwo = await database.sessionDuration.findAll({
transaction,
where: {
roundedLastUpdate: {
[Sequelize.Op.lt]: (now - 1000 * 60 * 60 * 24 * 3 /* 3 days */).toString()
}
},
attributes: [
'familyId',
'categoryId'
],
limit: 1000,
order: [['roundedLastUpdate', 'ASC']]
}).map((item) => ({
familyId: item.familyId,
categoryId: item.categoryId
}))
const categoriesToCleanUp = [ ...categoriesToCleanUpOne, ...categoriesToCleanUpTwo ]
const distinctCategoriesToCleanUp = uniqBy(categoriesToCleanUp, (item) => item.familyId + '_' + item.categoryId)
if (distinctCategoriesToCleanUp.length > 0) {
@@ -78,6 +99,18 @@ async function deleteOldUsedTimes ({ database }: {
}
})
await database.sessionDuration.destroy({
transaction,
where: {
[Sequelize.Op.or]: (
distinctCategoriesToCleanUp
),
roundedLastUpdate: {
[Sequelize.Op.lt]: (now - 1000 * 60 * 60 * 24 * 3 /* 3 days */).toString()
}
}
})
// invalidiate categories
await database.category.update({
usedTimesVersion: generateVersionId()