|
|
|
@ -2,7 +2,8 @@ import type { SortType } from 'nocodb-sdk';
|
|
|
|
|
import { NcError } from '~/helpers/catchError'; |
|
|
|
|
import { extractProps } from '~/helpers/extractProps'; |
|
|
|
|
import Noco from '~/Noco'; |
|
|
|
|
import { MetaTable } from '~/utils/globals'; |
|
|
|
|
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals'; |
|
|
|
|
import NocoCache from '~/cache/NocoCache'; |
|
|
|
|
|
|
|
|
|
// Store is used for storing key value pairs
|
|
|
|
|
export default class Store { |
|
|
|
@ -18,8 +19,30 @@ export default class Store {
|
|
|
|
|
Object.assign(this, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static get(key: string, ncMeta = Noco.ncMeta): Promise<Store> { |
|
|
|
|
return ncMeta.metaGet(null, null, MetaTable.STORE, { key }); |
|
|
|
|
public static async get( |
|
|
|
|
key: string, |
|
|
|
|
lookInCache = false, |
|
|
|
|
ncMeta = Noco.ncMeta, |
|
|
|
|
): Promise<Store> { |
|
|
|
|
// get from cache if lookInCache is true
|
|
|
|
|
if (lookInCache) { |
|
|
|
|
const storeData = |
|
|
|
|
key && |
|
|
|
|
(await NocoCache.get( |
|
|
|
|
`${CacheScope.STORE}:${key}`, |
|
|
|
|
CacheGetType.TYPE_OBJECT, |
|
|
|
|
)); |
|
|
|
|
if (storeData) return storeData; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const storeData = await ncMeta.metaGet(null, null, MetaTable.STORE, { |
|
|
|
|
key, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (lookInCache) |
|
|
|
|
await NocoCache.set(`${CacheScope.STORE}:${key}`, storeData); |
|
|
|
|
|
|
|
|
|
return storeData; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static async saveOrUpdate(store: Store, ncMeta = Noco.ncMeta) { |
|
|
|
@ -35,7 +58,7 @@ export default class Store {
|
|
|
|
|
'tag', |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
const existing = await Store.get(store.key, ncMeta); |
|
|
|
|
const existing = await Store.get(store.key,false, ncMeta); |
|
|
|
|
if (existing) { |
|
|
|
|
await ncMeta.metaUpdate(null, null, MetaTable.STORE, insertObj, { |
|
|
|
|
key: store.key, |
|
|
|
@ -43,5 +66,6 @@ export default class Store {
|
|
|
|
|
} else { |
|
|
|
|
await ncMeta.metaInsert(null, null, MetaTable.STORE, insertObj); |
|
|
|
|
} |
|
|
|
|
if (store.key) await NocoCache.del(`${CacheScope.STORE}:${store.key}`); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|