1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00

Optimize updating oauth tokens activity

This commit is contained in:
Chocobozzz 2025-09-10 15:16:40 +02:00
parent efa32646ed
commit bbc1afada5
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 10 additions and 14 deletions

View file

@ -185,7 +185,7 @@
"." "."
], ],
"sass": { "sass": {
"silenceDeprecations": [ "import", "mixed-decls", "color-functions", "global-builtin" ] "silenceDeprecations": [ "import", "color-functions", "global-builtin" ]
} }
}, },
"assets": [ "assets": [

View file

@ -7,7 +7,7 @@ export function getCSSConfig (root: string) {
api: 'modern-compiler', api: 'modern-compiler',
loadPaths: [ resolve(root, './src/sass/include') ], loadPaths: [ resolve(root, './src/sass/include') ],
// FIXME: Wait for bootstrap upgrade that fixes deprecated sass utils // FIXME: Wait for bootstrap upgrade that fixes deprecated sass utils
silenceDeprecations: [ 'import', 'mixed-decls', 'color-functions', 'global-builtin' ] silenceDeprecations: [ 'import', 'color-functions', 'global-builtin' ]
} }
} }
} }

View file

@ -3,7 +3,6 @@ import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js' import { AbstractScheduler } from './abstract-scheduler.js'
type UpdatePayload = { type UpdatePayload = {
id: number
lastActivityDate: Date lastActivityDate: Date
lastActivityIP: string lastActivityIP: string
lastActivityDevice: string lastActivityDevice: string
@ -14,29 +13,27 @@ export class UpdateTokenSessionScheduler extends AbstractScheduler {
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.UPDATE_TOKEN_SESSION protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.UPDATE_TOKEN_SESSION
private readonly toUpdate = new Set<UpdatePayload>() private toUpdate = new Map<number, UpdatePayload>()
private constructor () { private constructor () {
super() super()
} }
addToUpdate (payload: UpdatePayload) { addToUpdate (id: number, payload: UpdatePayload) {
this.toUpdate.add(payload) this.toUpdate.set(id, payload)
} }
protected async internalExecute () { protected async internalExecute () {
const toUpdate = Array.from(this.toUpdate) const entriesToUpdate = this.toUpdate.entries()
this.toUpdate.clear() this.toUpdate = new Map()
for (const payload of toUpdate) { for (const [ id, payload ] of entriesToUpdate) {
await OAuthTokenModel.update({ await OAuthTokenModel.update({
lastActivityDate: payload.lastActivityDate, lastActivityDate: payload.lastActivityDate,
lastActivityIP: payload.lastActivityIP, lastActivityIP: payload.lastActivityIP,
lastActivityDevice: payload.lastActivityDevice lastActivityDevice: payload.lastActivityDevice
}, { }, {
where: { where: { id },
id: payload.id
},
// Prevent tokens cache invalidation, we don't update fields that are meaningful for this cache // Prevent tokens cache invalidation, we don't update fields that are meaningful for this cache
hooks: false hooks: false
}) })

View file

@ -13,8 +13,7 @@ export function authenticate (req: express.Request, res: express.Response, next:
res.locals.oauth = { token } res.locals.oauth = { token }
res.locals.authenticated = true res.locals.authenticated = true
UpdateTokenSessionScheduler.Instance.addToUpdate({ UpdateTokenSessionScheduler.Instance.addToUpdate(token.id, {
id: token.id,
lastActivityDate: new Date(), lastActivityDate: new Date(),
lastActivityIP: req.ip, lastActivityIP: req.ip,
lastActivityDevice: req.header('user-agent') lastActivityDevice: req.header('user-agent')