refactor: normalise data (#756)

* chore: remove legal from bundle

* refactor: create normalised dataset

* refactor: cuesheet uses flat rundown

* refactor: multi-selection

* refactor: prevent stale data on server restart

* refactor: increase ID size

* chore: instrument operation

* chore: update csv tests

* fix: resolve directory to test-db (#758)
This commit is contained in:
Carlos Valente
2024-02-03 21:43:17 +01:00
committed by GitHub
parent 47a519bac1
commit 1890fc49d7
62 changed files with 1838 additions and 3341 deletions
@@ -1,67 +0,0 @@
import { runtimeCacheStore } from '../cachingStore.js';
describe('cachingStore()', () => {
beforeEach(() => {
runtimeCacheStore.clear(); // Clear the cache before each test
});
it('should check if an item is cached', () => {
// Add an item to the cache
runtimeCacheStore.setCached('key', 'value');
// Check if the item is cached
expect(runtimeCacheStore.checkCached('key')).toBe(true);
expect(runtimeCacheStore.checkCached('non-existent-key')).toBe(false);
});
it('should get an item from the cache', () => {
// Add an item to the cache
runtimeCacheStore.setCached('key', 'value');
// Get the item from the cache
const result = runtimeCacheStore.getCached('key', () => 'default-value');
// Check the returned value
expect(result).toBe('value');
});
it('should retrieve default value when item is not cached', () => {
// Get an item that is not in the cache
const result = runtimeCacheStore.getCached('non-existent-key', () => 'default-value');
// Check the returned value
expect(result).toBe('default-value');
});
it('should set an item in the cache', () => {
// Set an item in the cache
runtimeCacheStore.setCached('key', 'value');
// Check if the item is cached
expect(runtimeCacheStore.checkCached('key')).toBe(true);
});
it('should invalidate an item in the cache', () => {
// Add an item to the cache
runtimeCacheStore.setCached('key', 'value');
// Invalidate the item
runtimeCacheStore.invalidate('key');
// Check if the item is no longer cached
expect(runtimeCacheStore.checkCached('key')).toBe(false);
});
it('should clear the cache', () => {
// Add items to the cache
runtimeCacheStore.setCached('key1', 'value1');
runtimeCacheStore.setCached('key2', 'value2');
// Clear the cache
runtimeCacheStore.clear();
// Check if the cache is empty
expect(runtimeCacheStore.checkCached('key1')).toBe(false);
expect(runtimeCacheStore.checkCached('key2')).toBe(false);
});
});
-47
View File
@@ -1,47 +0,0 @@
interface CacheData {
data: unknown;
}
const runtimeCache: Map<string, CacheData> = new Map();
export function checkCached(key: string): boolean {
return runtimeCache.has(key);
}
export function getCached<T>(key: string, callback: () => T): T {
if (!runtimeCache.has(key)) {
try {
const data = callback();
runtimeCache.set(key, { data });
} catch (error) {
console.error(`Failed retrieving data from callback: ${error}`);
}
}
return runtimeCache.get(key).data as T;
}
export function setCached<T>(key: string, value: T): T {
runtimeCache.set(key, { data: value });
return value;
}
export function invalidate(key: string) {
runtimeCache.delete(key);
}
export function clear() {
runtimeCache.clear();
}
function createCacheStore() {
return {
checkCached,
getCached,
setCached,
invalidate,
clear,
};
}
export const runtimeCacheStore = createCacheStore();