1
0
Fork 0
mirror of synced 2024-09-08 05:31:47 +12:00

Clean code

This commit is contained in:
adrinr 2023-02-28 14:54:43 +01:00
parent c254c565e4
commit c1462a7c9c
2 changed files with 5 additions and 9 deletions

View file

@ -28,7 +28,7 @@ function makeCacheItem(doc: any, lastWrite: number | null = null): CacheItem {
return { doc, lastWrite: lastWrite || Date.now() }
}
export async function put(
async function put(
db: Database,
doc: Document,
writeRateMs: number = DEFAULT_WRITE_RATE_MS
@ -82,7 +82,7 @@ export async function put(
return { ok: true, id: output._id, rev: output._rev }
}
export async function get(db: Database, id: string): Promise<any> {
async function get(db: Database, id: string): Promise<any> {
const cache = await getCache()
const cacheKey = makeCacheKey(db, id)
let cacheItem: CacheItem = await cache.get(cacheKey)
@ -94,11 +94,7 @@ export async function get(db: Database, id: string): Promise<any> {
return cacheItem.doc
}
export async function remove(
db: Database,
docOrId: any,
rev?: any
): Promise<void> {
async function remove(db: Database, docOrId: any, rev?: any): Promise<void> {
const cache = await getCache()
if (!docOrId) {
throw new Error("No ID/Rev provided.")

View file

@ -24,7 +24,7 @@ const getClient = async (type: LockType): Promise<Redlock> => {
}
}
export const OPTIONS = {
const OPTIONS = {
TRY_ONCE: {
// immediately throws an error if the lock is already held
retryCount: 0,
@ -56,7 +56,7 @@ export const OPTIONS = {
},
}
export const newRedlock = async (opts: Options = {}) => {
const newRedlock = async (opts: Options = {}) => {
let options = { ...OPTIONS.DEFAULT, ...opts }
const redisWrapper = await getLockClient()
const client = redisWrapper.getClient()