mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 18:25:21 -04:00
Add caching of user-data (#568)
* Add caching of user-data for 600 seconds * Make cache-entry interface commonly usable * Extract revision types * Remove revision-cache rule * Use seconds as cache-time interval (Date.now uses milliseconds) * Fix import error * Extract cache logic into common cache-class * Add cache class that was forgotten to commit in last commit * Start adding unit tests * Fix bug detected during unit-testing * Add unit tests for cache * Made entry-limit test more explicit * Renamed files to lower-case starting letter
This commit is contained in:
parent
0f31c3b0b4
commit
091b225672
8 changed files with 156 additions and 31 deletions
|
@ -1,9 +1,7 @@
|
|||
import { Revision } from '../../../../api/revisions'
|
||||
import { Revision } from '../../../../api/revisions/types'
|
||||
import { getUserById } from '../../../../api/users'
|
||||
import { UserResponse } from '../../../../api/users/types'
|
||||
|
||||
const userResponseCache = new Map<string, UserResponse>()
|
||||
|
||||
export const downloadRevision = (noteId: string, revision: Revision | null): void => {
|
||||
if (!revision) {
|
||||
return
|
||||
|
@ -23,15 +21,9 @@ export const getUserDataForRevision = (authors: string[]): UserResponse[] => {
|
|||
if (index > 9) {
|
||||
return
|
||||
}
|
||||
const cacheEntry = userResponseCache.get(author)
|
||||
if (cacheEntry) {
|
||||
users.push(cacheEntry)
|
||||
return
|
||||
}
|
||||
getUserById(author)
|
||||
.then(userData => {
|
||||
users.push(userData)
|
||||
userResponseCache.set(author, userData)
|
||||
})
|
||||
.catch((error) => console.error(error))
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue