mirror of
https://github.com/outline/outline.git
synced 2026-05-08 02:50:30 -05:00
perf: Add cache for document structure (#9196)
* Normalize Collection.findByPk * Add caching of documentStructure * fix: Do not set cache before transaction is flushed * Mock Redis
This commit is contained in:
@@ -125,4 +125,8 @@ export class CacheHelper {
|
||||
public static getUnfurlKey(teamId: string, url = "") {
|
||||
return `unfurl:${teamId}:${url}`;
|
||||
}
|
||||
|
||||
public static getCollectionDocumentsKey(collectionId: string) {
|
||||
return `cd:${collectionId}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { Day } from "@shared/utils/time";
|
||||
|
||||
/**
|
||||
* A Mock Helper class for server-side cache management
|
||||
*/
|
||||
export class CacheHelper {
|
||||
// Default expiry time for cache data in seconds
|
||||
private static defaultDataExpiry = Day.seconds;
|
||||
|
||||
/**
|
||||
* Mocked method that resolves with the callback result
|
||||
*/
|
||||
public static async getDataOrSet<T>(
|
||||
key: string,
|
||||
callback: () => Promise<T | undefined>,
|
||||
_expiry: number,
|
||||
_lockTimeout: number
|
||||
): Promise<T | undefined> {
|
||||
return await callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocked method that resolves with undefined
|
||||
*/
|
||||
public static async getData<T>(_key: string): Promise<T | undefined> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocked method that resolves with void
|
||||
*/
|
||||
public static async setData<T>(_key: string, _data: T, _expiry?: number) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocked method that resolves with void
|
||||
*/
|
||||
public static async clearData(_prefix: string) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* These are real methods that don't require mocking as they don't
|
||||
* interact with Redis directly
|
||||
*/
|
||||
public static getUnfurlKey(teamId: string, url = "") {
|
||||
return `unfurl:${teamId}:${url}`;
|
||||
}
|
||||
|
||||
public static getCollectionDocumentsKey(collectionId: string) {
|
||||
return `cd:${collectionId}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
export class MutexLock {
|
||||
// Default expiry time for acquiring lock in milliseconds
|
||||
public static defaultLockTimeout = 4000;
|
||||
|
||||
/**
|
||||
* Returns the mock redlock instance
|
||||
*/
|
||||
public static get lock() {
|
||||
return {
|
||||
acquire: jest.fn().mockResolvedValue({
|
||||
release: jest.fn().mockResolvedValue(true),
|
||||
expiration: Date.now() + 10000,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
private static redlock: any;
|
||||
}
|
||||
Reference in New Issue
Block a user