Browse Source

fix: set before appending to list

pull/7464/head
mertmit 10 months ago
parent
commit
104cc9ea0d
  1. 14
      packages/nocodb/src/models/ApiToken.ts
  2. 15
      packages/nocodb/src/models/Base.ts
  3. 87
      packages/nocodb/src/models/Filter.ts
  4. 10
      packages/nocodb/src/models/FormViewColumn.ts
  5. 21
      packages/nocodb/src/models/GalleryViewColumn.ts
  6. 20
      packages/nocodb/src/models/GridViewColumn.ts
  7. 15
      packages/nocodb/src/models/Hook.ts
  8. 59
      packages/nocodb/src/models/HookFilter.ts
  9. 15
      packages/nocodb/src/models/KanbanViewColumn.ts
  10. 24
      packages/nocodb/src/models/LookupColumn.ts
  11. 10
      packages/nocodb/src/models/MapViewColumn.ts
  12. 32
      packages/nocodb/src/models/Model.ts
  13. 18
      packages/nocodb/src/models/ModelRoleVisibility.ts
  14. 24
      packages/nocodb/src/models/RollupColumn.ts
  15. 17
      packages/nocodb/src/models/SelectOption.ts
  16. 29
      packages/nocodb/src/models/Sort.ts
  17. 15
      packages/nocodb/src/models/View.ts

14
packages/nocodb/src/models/ApiToken.ts

@ -33,12 +33,14 @@ export default class ApiToken implements ApiTokenType {
token,
fk_user_id: apiToken.fk_user_id,
});
await NocoCache.appendToList(
CacheScope.API_TOKEN,
[],
`${CacheScope.API_TOKEN}:${token}`,
);
return this.getByToken(token);
return this.getByToken(token).then(async (apiToken) => {
await NocoCache.appendToList(
CacheScope.API_TOKEN,
[],
`${CacheScope.API_TOKEN}:${token}`,
);
return apiToken;
});
}
static async list(userId: string, ncMeta = Noco.ncMeta) {

15
packages/nocodb/src/models/Base.ts

@ -63,12 +63,6 @@ export default class Base implements BaseType {
insertObj,
);
await NocoCache.appendToList(
CacheScope.PROJECT,
[],
`${CacheScope.PROJECT}:${baseId}`,
);
for (const source of base.sources) {
await Source.createBase(
{
@ -81,7 +75,14 @@ export default class Base implements BaseType {
}
await NocoCache.del(CacheScope.INSTANCE_META);
return this.getWithInfo(baseId, ncMeta);
return this.getWithInfo(baseId, ncMeta).then(async (base) => {
await NocoCache.appendToList(
CacheScope.PROJECT,
[],
`${CacheScope.PROJECT}:${baseId}`,
);
return base;
});
}
static async list(

87
packages/nocodb/src/models/Filter.ts

@ -144,35 +144,16 @@ export default class Filter implements FilterType {
if (!value) {
/* get from db */
value = await ncMeta.metaGet2(null, null, MetaTable.FILTER_EXP, id);
// pushing calls for Promise.all
const p = [];
/* store in redis */
p.push(NocoCache.set(key, value));
/* append key to relevant lists */
if (filter.fk_view_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_view_id],
key,
),
);
}
if (filter.fk_hook_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_hook_id],
key,
),
);
}
if (filter.fk_parent_id) {
await NocoCache.set(key, value).then(async () => {
/* append key to relevant lists */
const p = [];
if (filter.fk_view_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_view_id, filter.fk_parent_id],
[filter.fk_view_id],
key,
),
);
@ -181,29 +162,49 @@ export default class Filter implements FilterType {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_hook_id, filter.fk_parent_id],
[filter.fk_hook_id],
key,
),
);
}
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_parent_id],
key,
),
);
}
if (filter.fk_column_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_column_id],
key,
),
);
}
await Promise.all(p);
if (filter.fk_parent_id) {
if (filter.fk_view_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_view_id, filter.fk_parent_id],
key,
),
);
}
if (filter.fk_hook_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_hook_id, filter.fk_parent_id],
key,
),
);
}
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_parent_id],
key,
),
);
}
if (filter.fk_column_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_column_id],
key,
),
);
}
await Promise.all(p);
});
}
// on new filter creation delete any optimised single query cache

10
packages/nocodb/src/models/FormViewColumn.ts

@ -99,18 +99,14 @@ export default class FormViewColumn implements FormColumnType {
await NocoCache.set(`${CacheScope.FORM_VIEW_COLUMN}:${fk_column_id}`, id);
// if cache is not present skip pushing it into the list to avoid unexpected behaviour
const { list } = await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [
column.fk_view_id,
]);
if (list?.length)
return this.get(id, ncMeta).then(async (viewColumn) => {
await NocoCache.appendToList(
CacheScope.FORM_VIEW_COLUMN,
[column.fk_view_id],
`${CacheScope.FORM_VIEW_COLUMN}:${id}`,
);
return this.get(id, ncMeta);
return viewColumn;
});
}
public static async list(

21
packages/nocodb/src/models/GalleryViewColumn.ts

@ -78,25 +78,20 @@ export default class GalleryViewColumn {
id,
);
// if cache is not present skip pushing it into the list to avoid unexpected behaviour
const { list } = await NocoCache.getList(CacheScope.GALLERY_VIEW_COLUMN, [
column.fk_view_id,
]);
if (list?.length)
await NocoCache.appendToList(
CacheScope.GALLERY_VIEW_COLUMN,
[column.fk_view_id],
`${CacheScope.GALLERY_VIEW_COLUMN}:${id}`,
);
// on new view column, delete any optimised single query cache
{
const view = await View.get(column.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]);
}
return this.get(id, ncMeta);
return this.get(id, ncMeta).then(async (viewColumn) => {
await NocoCache.appendToList(
CacheScope.GALLERY_VIEW_COLUMN,
[column.fk_view_id],
`${CacheScope.GALLERY_VIEW_COLUMN}:${id}`,
);
return viewColumn;
});
}
public static async list(

20
packages/nocodb/src/models/GridViewColumn.ts

@ -109,17 +109,6 @@ export default class GridViewColumn implements GridColumnType {
await NocoCache.set(`${CacheScope.GRID_VIEW_COLUMN}:${fk_column_id}`, id);
// if cache is not present skip pushing it into the list to avoid unexpected behaviour
const { list } = await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [
column.fk_view_id,
]);
if (list.length)
await NocoCache.appendToList(
CacheScope.GRID_VIEW_COLUMN,
[column.fk_view_id],
`${CacheScope.GRID_VIEW_COLUMN}:${id}`,
);
await View.fixPVColumnForView(column.fk_view_id, ncMeta);
// on new view column, delete any optimised single query cache
@ -128,7 +117,14 @@ export default class GridViewColumn implements GridColumnType {
await View.clearSingleQueryCache(view.fk_model_id, [view]);
}
return this.get(id, ncMeta);
return this.get(id, ncMeta).then(async (viewColumn) => {
await NocoCache.appendToList(
CacheScope.GRID_VIEW_COLUMN,
[column.fk_view_id],
`${CacheScope.GRID_VIEW_COLUMN}:${id}`,
);
return viewColumn;
});
}
static async update(

15
packages/nocodb/src/models/Hook.ts

@ -161,13 +161,14 @@ export default class Hook implements HookType {
insertObj,
);
await NocoCache.appendToList(
CacheScope.HOOK,
[hook.fk_model_id],
`${CacheScope.HOOK}:${id}`,
);
return this.get(id, ncMeta);
return this.get(id, ncMeta).then(async (hook) => {
await NocoCache.appendToList(
CacheScope.HOOK,
[hook.fk_model_id],
`${CacheScope.HOOK}:${id}`,
);
return hook;
});
}
public static async update(

59
packages/nocodb/src/models/HookFilter.ts

@ -100,40 +100,45 @@ export default class Filter {
if (!value) {
/* get from db */
value = await ncMeta.metaGet2(null, null, MetaTable.FILTER_EXP, id);
// pushing calls for Promise.all
const p = [];
/* store in redis */
p.push(NocoCache.set(key, value));
/* append key to relevant lists */
p.push(
NocoCache.appendToList(CacheScope.FILTER_EXP, [filter.fk_view_id], key),
);
if (filter.fk_parent_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_view_id, filter.fk_parent_id],
key,
),
);
await NocoCache.set(key, value).then(async () => {
/* append key to relevant lists */
const p = [];
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_parent_id],
[filter.fk_view_id],
key,
),
);
}
if (filter.fk_column_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_column_id],
key,
),
);
}
await Promise.all(p);
if (filter.fk_parent_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_view_id, filter.fk_parent_id],
key,
),
);
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_parent_id],
key,
),
);
}
if (filter.fk_column_id) {
p.push(
NocoCache.appendToList(
CacheScope.FILTER_EXP,
[filter.fk_column_id],
key,
),
);
}
await Promise.all(p);
});
}
return new Filter(value);
}

15
packages/nocodb/src/models/KanbanViewColumn.ts

@ -72,13 +72,14 @@ export default class KanbanViewColumn implements KanbanColumnType {
await NocoCache.set(`${CacheScope.KANBAN_VIEW_COLUMN}:${fk_column_id}`, id);
await NocoCache.appendToList(
CacheScope.KANBAN_VIEW_COLUMN,
[column.fk_view_id],
`${CacheScope.KANBAN_VIEW_COLUMN}:${id}`,
);
return this.get(id, ncMeta);
return this.get(id, ncMeta).then(async (kanbanViewColumn) => {
await NocoCache.appendToList(
CacheScope.KANBAN_VIEW_COLUMN,
[column.fk_view_id],
`${CacheScope.KANBAN_VIEW_COLUMN}:${id}`,
);
return kanbanViewColumn;
});
}
public static async list(

24
packages/nocodb/src/models/LookupColumn.ts

@ -38,19 +38,21 @@ export default class LookupColumn implements LookupType {
await ncMeta.metaInsert2(null, null, MetaTable.COL_LOOKUP, insertObj);
await NocoCache.appendToList(
CacheScope.COL_LOOKUP,
[data.fk_lookup_column_id],
`${CacheScope.COL_LOOKUP}:${data.fk_column_id}`,
);
return this.read(data.fk_column_id, ncMeta).then(async (lookupColumn) => {
await NocoCache.appendToList(
CacheScope.COL_LOOKUP,
[data.fk_lookup_column_id],
`${CacheScope.COL_LOOKUP}:${data.fk_column_id}`,
);
await NocoCache.appendToList(
CacheScope.COL_LOOKUP,
[data.fk_relation_column_id],
`${CacheScope.COL_LOOKUP}:${data.fk_column_id}`,
);
await NocoCache.appendToList(
CacheScope.COL_LOOKUP,
[data.fk_relation_column_id],
`${CacheScope.COL_LOOKUP}:${data.fk_column_id}`,
);
return this.read(data.fk_column_id, ncMeta);
return lookupColumn;
});
}
public static async read(columnId: string, ncMeta = Noco.ncMeta) {

10
packages/nocodb/src/models/MapViewColumn.ts

@ -66,18 +66,14 @@ export default class MapViewColumn {
await NocoCache.set(`${CacheScope.MAP_VIEW_COLUMN}:${fk_column_id}`, id);
// if cache is not present skip pushing it into the list to avoid unexpected behaviour
const { list } = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [
column.fk_view_id,
]);
if (list?.length)
return this.get(id, ncMeta).then(async (viewCol) => {
await NocoCache.appendToList(
CacheScope.MAP_VIEW_COLUMN,
[column.fk_view_id],
`${CacheScope.MAP_VIEW_COLUMN}:${id}`,
);
return this.get(id, ncMeta);
return viewCol;
});
}
public static async list(

32
packages/nocodb/src/models/Model.ts

@ -146,20 +146,6 @@ export default class Model implements TableType {
MetaTable.MODELS,
insertObj,
);
if (sourceId) {
await NocoCache.appendToList(
CacheScope.MODEL,
[baseId, sourceId],
`${CacheScope.MODEL}:${id}`,
);
}
// cater cases where sourceId is not required
// e.g. xcVisibilityMetaGet
await NocoCache.appendToList(
CacheScope.MODEL,
[baseId],
`${CacheScope.MODEL}:${id}`,
);
const view = await View.insert(
{
@ -175,7 +161,23 @@ export default class Model implements TableType {
await Column.insert({ ...column, fk_model_id: id, view } as any, ncMeta);
}
return this.getWithInfo({ id }, ncMeta);
return this.getWithInfo({ id }, ncMeta).then(async (model) => {
if (sourceId) {
await NocoCache.appendToList(
CacheScope.MODEL,
[baseId, sourceId],
`${CacheScope.MODEL}:${id}`,
);
}
// cater cases where sourceId is not required
// e.g. xcVisibilityMetaGet
await NocoCache.appendToList(
CacheScope.MODEL,
[baseId],
`${CacheScope.MODEL}:${id}`,
);
return model;
});
}
public static async list(

18
packages/nocodb/src/models/ModelRoleVisibility.ts

@ -155,22 +155,22 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType {
insertObj,
);
const key = `${CacheScope.MODEL_ROLE_VISIBILITY}:${body.fk_view_id}:${body.role}`;
insertObj.id = result.id;
await NocoCache.appendToList(
CacheScope.MODEL_ROLE_VISIBILITY,
[insertObj.base_id],
key,
);
return this.get(
{
fk_view_id: body.fk_view_id,
role: body.role,
},
ncMeta,
);
).then(async (modelRoleVisibility) => {
const key = `${CacheScope.MODEL_ROLE_VISIBILITY}:${body.fk_view_id}:${body.role}`;
await NocoCache.appendToList(
CacheScope.MODEL_ROLE_VISIBILITY,
[insertObj.base_id],
key,
);
return modelRoleVisibility;
});
}
}

24
packages/nocodb/src/models/RollupColumn.ts

@ -38,19 +38,21 @@ export default class RollupColumn implements RollupType {
]);
await ncMeta.metaInsert2(null, null, MetaTable.COL_ROLLUP, insertObj);
await NocoCache.appendToList(
CacheScope.COL_ROLLUP,
[data.fk_rollup_column_id],
`${CacheScope.COL_ROLLUP}:${data.fk_column_id}`,
);
return this.read(data.fk_column_id, ncMeta).then(async (rollupColumn) => {
await NocoCache.appendToList(
CacheScope.COL_ROLLUP,
[data.fk_rollup_column_id],
`${CacheScope.COL_ROLLUP}:${data.fk_column_id}`,
);
await NocoCache.appendToList(
CacheScope.COL_ROLLUP,
[data.fk_relation_column_id],
`${CacheScope.COL_ROLLUP}:${data.fk_column_id}`,
);
await NocoCache.appendToList(
CacheScope.COL_ROLLUP,
[data.fk_relation_column_id],
`${CacheScope.COL_ROLLUP}:${data.fk_column_id}`,
);
return this.read(data.fk_column_id, ncMeta);
return rollupColumn;
});
}
public static async read(columnId: string, ncMeta = Noco.ncMeta) {

17
packages/nocodb/src/models/SelectOption.ts

@ -34,13 +34,14 @@ export default class SelectOption implements SelectOptionType {
insertObj,
);
await NocoCache.appendToList(
CacheScope.COL_SELECT_OPTION,
[data.fk_column_id],
`${CacheScope.COL_SELECT_OPTION}:${id}`,
);
return this.get(id, ncMeta);
return this.get(id, ncMeta).then(async (selectOption) => {
await NocoCache.appendToList(
CacheScope.COL_SELECT_OPTION,
[data.fk_column_id],
`${CacheScope.COL_SELECT_OPTION}:${id}`,
);
return selectOption;
});
}
public static async bulkInsert(
@ -68,12 +69,12 @@ export default class SelectOption implements SelectOptionType {
);
for (const d of bulkData) {
await NocoCache.set(`${CacheScope.COL_SELECT_OPTION}:${d.id}`, d);
await NocoCache.appendToList(
CacheScope.COL_SELECT_OPTION,
[d.fk_column_id],
`${CacheScope.COL_SELECT_OPTION}:${d.id}`,
);
await NocoCache.set(`${CacheScope.COL_SELECT_OPTION}:${d.id}`, d);
}
return true;

29
packages/nocodb/src/models/Sort.ts

@ -92,27 +92,28 @@ export default class Sort {
},
});
await NocoCache.setList(CacheScope.SORT, [sortObj.fk_view_id], sortList);
} else {
await NocoCache.appendToList(
CacheScope.SORT,
[sortObj.fk_view_id],
`${CacheScope.SORT}:${row.id}`,
);
await NocoCache.appendToList(
CacheScope.SORT,
[sortObj.fk_column_id],
`${CacheScope.SORT}:${row.id}`,
);
}
// on insert, delete any optimised single query cache
{
const view = await View.get(row.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]);
}
return this.get(row.id, ncMeta);
return this.get(row.id, ncMeta).then(async (sort) => {
if (!sortObj.push_to_top) {
await NocoCache.appendToList(
CacheScope.SORT,
[sortObj.fk_view_id],
`${CacheScope.SORT}:${row.id}`,
);
await NocoCache.appendToList(
CacheScope.SORT,
[sortObj.fk_column_id],
`${CacheScope.SORT}:${row.id}`,
);
}
return sort;
});
}
public getColumn(): Promise<Column> {

15
packages/nocodb/src/models/View.ts

@ -319,12 +319,6 @@ export default class View implements ViewType {
insertObj,
);
await NocoCache.appendToList(
CacheScope.VIEW,
[view.fk_model_id],
`${CacheScope.VIEW}:${view_id}`,
);
let columns: any[] = await (
await Model.getByIdOrName({ id: view.fk_model_id }, ncMeta)
).getColumns(ncMeta);
@ -506,7 +500,14 @@ export default class View implements ViewType {
ncMeta,
);
return View.get(view_id, ncMeta);
return View.get(view_id, ncMeta).then(async (v) => {
await NocoCache.appendToList(
CacheScope.VIEW,
[view.fk_model_id],
`${CacheScope.VIEW}:${view_id}`,
);
return v;
});
}
static async insertColumnToAllViews(

Loading…
Cancel
Save