Browse Source

fix: set before appending to list

pull/7464/head
mertmit 11 months ago
parent
commit
104cc9ea0d
  1. 4
      packages/nocodb/src/models/ApiToken.ts
  2. 15
      packages/nocodb/src/models/Base.ts
  3. 7
      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. 5
      packages/nocodb/src/models/Hook.ts
  8. 13
      packages/nocodb/src/models/HookFilter.ts
  9. 5
      packages/nocodb/src/models/KanbanViewColumn.ts
  10. 4
      packages/nocodb/src/models/LookupColumn.ts
  11. 10
      packages/nocodb/src/models/MapViewColumn.ts
  12. 32
      packages/nocodb/src/models/Model.ts
  13. 16
      packages/nocodb/src/models/ModelRoleVisibility.ts
  14. 4
      packages/nocodb/src/models/RollupColumn.ts
  15. 7
      packages/nocodb/src/models/SelectOption.ts
  16. 21
      packages/nocodb/src/models/Sort.ts
  17. 15
      packages/nocodb/src/models/View.ts

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

@ -33,12 +33,14 @@ export default class ApiToken implements ApiTokenType {
token, token,
fk_user_id: apiToken.fk_user_id, fk_user_id: apiToken.fk_user_id,
}); });
return this.getByToken(token).then(async (apiToken) => {
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.API_TOKEN, CacheScope.API_TOKEN,
[], [],
`${CacheScope.API_TOKEN}:${token}`, `${CacheScope.API_TOKEN}:${token}`,
); );
return this.getByToken(token); return apiToken;
});
} }
static async list(userId: string, ncMeta = Noco.ncMeta) { 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, insertObj,
); );
await NocoCache.appendToList(
CacheScope.PROJECT,
[],
`${CacheScope.PROJECT}:${baseId}`,
);
for (const source of base.sources) { for (const source of base.sources) {
await Source.createBase( await Source.createBase(
{ {
@ -81,7 +75,14 @@ export default class Base implements BaseType {
} }
await NocoCache.del(CacheScope.INSTANCE_META); 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( static async list(

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

@ -144,11 +144,11 @@ export default class Filter implements FilterType {
if (!value) { if (!value) {
/* get from db */ /* get from db */
value = await ncMeta.metaGet2(null, null, MetaTable.FILTER_EXP, id); value = await ncMeta.metaGet2(null, null, MetaTable.FILTER_EXP, id);
// pushing calls for Promise.all
const p = [];
/* store in redis */ /* store in redis */
p.push(NocoCache.set(key, value)); await NocoCache.set(key, value).then(async () => {
/* append key to relevant lists */ /* append key to relevant lists */
const p = [];
if (filter.fk_view_id) { if (filter.fk_view_id) {
p.push( p.push(
NocoCache.appendToList( NocoCache.appendToList(
@ -204,6 +204,7 @@ export default class Filter implements FilterType {
); );
} }
await Promise.all(p); await Promise.all(p);
});
} }
// on new filter creation delete any optimised single query cache // 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); 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 return this.get(id, ncMeta).then(async (viewColumn) => {
const { list } = await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [
column.fk_view_id,
]);
if (list?.length)
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.FORM_VIEW_COLUMN, CacheScope.FORM_VIEW_COLUMN,
[column.fk_view_id], [column.fk_view_id],
`${CacheScope.FORM_VIEW_COLUMN}:${id}`, `${CacheScope.FORM_VIEW_COLUMN}:${id}`,
); );
return this.get(id, ncMeta); return viewColumn;
});
} }
public static async list( public static async list(

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

@ -78,25 +78,20 @@ export default class GalleryViewColumn {
id, 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 // on new view column, delete any optimised single query cache
{ {
const view = await View.get(column.fk_view_id, ncMeta); const view = await View.get(column.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]); 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( 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); 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); await View.fixPVColumnForView(column.fk_view_id, ncMeta);
// on new view column, delete any optimised single query cache // 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]); 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( static async update(

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

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

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

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

5
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.set(`${CacheScope.KANBAN_VIEW_COLUMN}:${fk_column_id}`, id);
return this.get(id, ncMeta).then(async (kanbanViewColumn) => {
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.KANBAN_VIEW_COLUMN, CacheScope.KANBAN_VIEW_COLUMN,
[column.fk_view_id], [column.fk_view_id],
`${CacheScope.KANBAN_VIEW_COLUMN}:${id}`, `${CacheScope.KANBAN_VIEW_COLUMN}:${id}`,
); );
return kanbanViewColumn;
return this.get(id, ncMeta); });
} }
public static async list( public static async list(

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

@ -38,6 +38,7 @@ export default class LookupColumn implements LookupType {
await ncMeta.metaInsert2(null, null, MetaTable.COL_LOOKUP, insertObj); await ncMeta.metaInsert2(null, null, MetaTable.COL_LOOKUP, insertObj);
return this.read(data.fk_column_id, ncMeta).then(async (lookupColumn) => {
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.COL_LOOKUP, CacheScope.COL_LOOKUP,
[data.fk_lookup_column_id], [data.fk_lookup_column_id],
@ -50,7 +51,8 @@ export default class LookupColumn implements LookupType {
`${CacheScope.COL_LOOKUP}:${data.fk_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) { 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); 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 return this.get(id, ncMeta).then(async (viewCol) => {
const { list } = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [
column.fk_view_id,
]);
if (list?.length)
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.MAP_VIEW_COLUMN, CacheScope.MAP_VIEW_COLUMN,
[column.fk_view_id], [column.fk_view_id],
`${CacheScope.MAP_VIEW_COLUMN}:${id}`, `${CacheScope.MAP_VIEW_COLUMN}:${id}`,
); );
return viewCol;
return this.get(id, ncMeta); });
} }
public static async list( public static async list(

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

@ -146,20 +146,6 @@ export default class Model implements TableType {
MetaTable.MODELS, MetaTable.MODELS,
insertObj, 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( 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); 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( public static async list(

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

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

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

@ -38,6 +38,7 @@ export default class RollupColumn implements RollupType {
]); ]);
await ncMeta.metaInsert2(null, null, MetaTable.COL_ROLLUP, insertObj); await ncMeta.metaInsert2(null, null, MetaTable.COL_ROLLUP, insertObj);
return this.read(data.fk_column_id, ncMeta).then(async (rollupColumn) => {
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.COL_ROLLUP, CacheScope.COL_ROLLUP,
[data.fk_rollup_column_id], [data.fk_rollup_column_id],
@ -50,7 +51,8 @@ export default class RollupColumn implements RollupType {
`${CacheScope.COL_ROLLUP}:${data.fk_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) { public static async read(columnId: string, ncMeta = Noco.ncMeta) {

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

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

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

@ -92,27 +92,28 @@ export default class Sort {
}, },
}); });
await NocoCache.setList(CacheScope.SORT, [sortObj.fk_view_id], sortList); await NocoCache.setList(CacheScope.SORT, [sortObj.fk_view_id], sortList);
} else { }
// 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).then(async (sort) => {
if (!sortObj.push_to_top) {
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.SORT, CacheScope.SORT,
[sortObj.fk_view_id], [sortObj.fk_view_id],
`${CacheScope.SORT}:${row.id}`, `${CacheScope.SORT}:${row.id}`,
); );
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.SORT, CacheScope.SORT,
[sortObj.fk_column_id], [sortObj.fk_column_id],
`${CacheScope.SORT}:${row.id}`, `${CacheScope.SORT}:${row.id}`,
); );
} }
return sort;
// 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);
} }
public getColumn(): Promise<Column> { public getColumn(): Promise<Column> {

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

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

Loading…
Cancel
Save