Browse Source

fix: use cache update on missing places

pull/7727/head
mertmit 9 months ago
parent
commit
012a23563e
  1. 17
      packages/nocodb/src/models/BaseUser.ts
  2. 17
      packages/nocodb/src/models/CalendarViewColumn.ts
  3. 41
      packages/nocodb/src/models/Column.ts
  4. 25
      packages/nocodb/src/models/FormViewColumn.ts
  5. 136
      packages/nocodb/src/models/Model.ts
  6. 20
      packages/nocodb/src/models/ModelRoleVisibility.ts
  7. 15
      packages/nocodb/src/models/Sort.ts
  8. 28
      packages/nocodb/src/models/Source.ts
  9. 116
      packages/nocodb/src/models/View.ts
  10. 27
      packages/nocodb/src/utils/modelUtils.ts

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

@ -205,17 +205,8 @@ export default class BaseUser {
roles: string, roles: string,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
// get existing cache
const key = `${CacheScope.BASE_USER}:${baseId}:${userId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
o.roles = roles;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
return await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.PROJECT_USERS, MetaTable.PROJECT_USERS,
@ -227,6 +218,12 @@ export default class BaseUser {
base_id: baseId, base_id: baseId,
}, },
); );
await NocoCache.update(`${CacheScope.BASE_USER}:${baseId}:${userId}`, {
roles,
});
return res;
} }
static async update( static async update(

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

@ -162,21 +162,20 @@ export default class CalendarViewColumn {
'italic', 'italic',
]); ]);
// get existing cache
const key = `${CacheScope.CALENDAR_VIEW_COLUMN}:${columnId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
Object.assign(o, updateObj);
// set cache
await NocoCache.set(key, o);
}
// update meta // update meta
return await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.CALENDAR_VIEW_COLUMNS, MetaTable.CALENDAR_VIEW_COLUMNS,
updateObj, updateObj,
columnId, columnId,
); );
await NocoCache.update(
`${CacheScope.CALENDAR_VIEW_COLUMN}:${columnId}`,
updateObj,
);
return res;
} }
} }

41
packages/nocodb/src/models/Column.ts

@ -32,7 +32,6 @@ import {
parseMetaProp, parseMetaProp,
prepareForDb, prepareForDb,
prepareForResponse, prepareForResponse,
stringifyMetaProp,
} from '~/utils/modelUtils'; } from '~/utils/modelUtils';
import { getFormulasReferredTheColumn } from '~/helpers/formulaHelpers'; import { getFormulasReferredTheColumn } from '~/helpers/formulaHelpers';
@ -1139,15 +1138,6 @@ export default class Column<T = any> implements ColumnType {
{ title }: { title: string }, { title }: { title: string },
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
// get existing cache
const key = `${CacheScope.COLUMN}:${colId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.title = title;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, //column.base_id || column.source_id, null, //column.base_id || column.source_id,
@ -1159,6 +1149,8 @@ export default class Column<T = any> implements ColumnType {
colId, colId,
); );
await NocoCache.update(`${CacheScope.COLUMN}:${colId}`, { title });
const column = await Column.get({ colId }, ncMeta); const column = await Column.get({ colId }, ncMeta);
await View.clearSingleQueryCache(column.fk_model_id); await View.clearSingleQueryCache(column.fk_model_id);
@ -1219,15 +1211,6 @@ export default class Column<T = any> implements ColumnType {
system = true, system = true,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
// get existing cache
const key = `${CacheScope.COLUMN}:${colId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.system = system;
// set cache
await NocoCache.set(key, o);
}
// update system field in meta db // update system field in meta db
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
@ -1238,6 +1221,8 @@ export default class Column<T = any> implements ColumnType {
}, },
colId, colId,
); );
await NocoCache.update(`${CacheScope.COLUMN}:${colId}`, { system });
} }
static getMaxColumnNameLength(sqlClientType: string) { static getMaxColumnNameLength(sqlClientType: string) {
@ -1257,25 +1242,19 @@ export default class Column<T = any> implements ColumnType {
{ colId, meta }: { colId: string; meta: any }, { colId, meta }: { colId: string; meta: any },
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
// get existing cache
const key = `${CacheScope.COLUMN}:${colId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update meta
o.meta = meta;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.COLUMNS, MetaTable.COLUMNS,
{ prepareForDb({ meta }),
meta: stringifyMetaProp({ meta }),
},
colId, colId,
); );
await NocoCache.update(
`${CacheScope.COLUMN}:${colId}`,
prepareForResponse({ meta }),
);
} }
static async bulkInsert( static async bulkInsert(

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

@ -10,6 +10,7 @@ import NocoCache from '~/cache/NocoCache';
import { extractProps } from '~/helpers/extractProps'; import { extractProps } from '~/helpers/extractProps';
import { deserializeJSON, serializeJSON } from '~/utils/serialize'; import { deserializeJSON, serializeJSON } from '~/utils/serialize';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals'; import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
import { prepareForDb, prepareForResponse } from '~/utils/modelUtils';
export default class FormViewColumn implements FormColumnType { export default class FormViewColumn implements FormColumnType {
id?: string; id?: string;
@ -168,26 +169,20 @@ export default class FormViewColumn implements FormColumnType {
'enable_scanner', 'enable_scanner',
]); ]);
// get existing cache
const key = `${CacheScope.FORM_VIEW_COLUMN}:${columnId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
Object.assign(o, updateObj);
// set cache
await NocoCache.set(key, o);
}
if (updateObj.meta) {
updateObj.meta = serializeJSON(updateObj.meta);
}
// update meta // update meta
return await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.FORM_VIEW_COLUMNS, MetaTable.FORM_VIEW_COLUMNS,
updateObj, prepareForDb(updateObj),
columnId, columnId,
); );
await NocoCache.update(
`${CacheScope.FORM_VIEW_COLUMN}:${columnId}`,
prepareForResponse(updateObj),
);
return res;
} }
} }

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

@ -26,7 +26,11 @@ import {
import NocoCache from '~/cache/NocoCache'; import NocoCache from '~/cache/NocoCache';
import Noco from '~/Noco'; import Noco from '~/Noco';
import { BaseModelSqlv2 } from '~/db/BaseModelSqlv2'; import { BaseModelSqlv2 } from '~/db/BaseModelSqlv2';
import { parseMetaProp } from '~/utils/modelUtils'; import {
parseMetaProp,
prepareForDb,
prepareForResponse,
} from '~/utils/modelUtils';
export default class Model implements TableType { export default class Model implements TableType {
copy_enabled: BoolType; copy_enabled: BoolType;
@ -641,27 +645,8 @@ export default class Model implements TableType {
if (!table_name) { if (!table_name) {
NcError.badRequest("Missing 'table_name' property in body"); NcError.badRequest("Missing 'table_name' property in body");
} }
// get existing cache
const key = `${CacheScope.MODEL}:${tableId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
let oldModel = { ...o };
// update alias
if (o) {
o.title = title;
o.table_name = table_name;
// set cache
await NocoCache.set(key, o);
} else {
oldModel = await this.get(tableId);
}
// delete alias cache const oldModel = await this.get(tableId, ncMeta);
await NocoCache.del([
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.id}`,
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.source_id}:${oldModel.id}`,
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.title}`,
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.source_id}:${oldModel.title}`,
]);
// set meta // set meta
const res = await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
@ -675,6 +660,19 @@ export default class Model implements TableType {
tableId, tableId,
); );
await NocoCache.update(`${CacheScope.MODEL}:${tableId}`, {
title,
table_name,
});
// delete alias cache
await NocoCache.del([
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.id}`,
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.source_id}:${oldModel.id}`,
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.title}`,
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.source_id}:${oldModel.title}`,
]);
// clear all the cached query under this model // clear all the cached query under this model
await View.clearSingleQueryCache(tableId); await View.clearSingleQueryCache(tableId);
@ -693,17 +691,8 @@ export default class Model implements TableType {
} }
static async markAsMmTable(tableId, isMm = true, ncMeta = Noco.ncMeta) { static async markAsMmTable(tableId, isMm = true, ncMeta = Noco.ncMeta) {
// get existing cache
const key = `${CacheScope.MODEL}:${tableId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
// update alias
if (o) {
o.mm = isMm;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
return await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.MODELS, MetaTable.MODELS,
@ -712,6 +701,12 @@ export default class Model implements TableType {
}, },
tableId, tableId,
); );
await NocoCache.update(`${CacheScope.MODEL}:${tableId}`, {
mm: isMm,
});
return res;
} }
async getAliasColMapping() { async getAliasColMapping() {
@ -737,16 +732,8 @@ export default class Model implements TableType {
order: number, order: number,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
// get existing cache
const key = `${CacheScope.MODEL}:${tableId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
o.order = order;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
return await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.MODELS, MetaTable.MODELS,
@ -755,6 +742,12 @@ export default class Model implements TableType {
}, },
tableId, tableId,
); );
await NocoCache.update(`${CacheScope.MODEL}:${tableId}`, {
order,
});
return res;
} }
static async updatePrimaryColumn( static async updatePrimaryColumn(
@ -769,14 +762,6 @@ export default class Model implements TableType {
// drop existing primary column/s // drop existing primary column/s
for (const col of model.columns?.filter((c) => c.pv) || []) { for (const col of model.columns?.filter((c) => c.pv) || []) {
// get existing cache
const key = `${CacheScope.COLUMN}:${col.id}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
o.pv = false;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
@ -787,16 +772,12 @@ export default class Model implements TableType {
}, },
col.id, col.id,
); );
}
// get existing cache await NocoCache.update(`${CacheScope.COLUMN}:${col.id}`, {
const key = `${CacheScope.COLUMN}:${newPvCol.id}`; pv: false,
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); });
if (o) {
o.pv = true;
// set cache
await NocoCache.set(key, o);
} }
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
@ -808,6 +789,10 @@ export default class Model implements TableType {
newPvCol.id, newPvCol.id,
); );
await NocoCache.update(`${CacheScope.COLUMN}:${newPvCol.id}`, {
pv: true,
});
const grid_views_with_column = await ncMeta.metaList2( const grid_views_with_column = await ncMeta.metaList2(
null, null,
null, null,
@ -829,14 +814,6 @@ export default class Model implements TableType {
} }
static async setAsMm(id: any, ncMeta = Noco.ncMeta) { static async setAsMm(id: any, ncMeta = Noco.ncMeta) {
// get existing cache
const key = `${CacheScope.MODEL}:${id}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
o.mm = true;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
@ -847,6 +824,10 @@ export default class Model implements TableType {
}, },
id, id,
); );
await NocoCache.update(`${CacheScope.MODEL}:${id}`, {
mm: true,
});
} }
static async getByAliasOrId( static async getByAliasOrId(
@ -976,26 +957,25 @@ export default class Model implements TableType {
meta: string | Record<string, any>, meta: string | Record<string, any>,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
// get existing cache
const key = `${CacheScope.MODEL}:${tableId}`;
const existingCache = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (existingCache) {
try {
existingCache.meta = typeof meta === 'string' ? JSON.parse(meta) : meta;
// set cache
await NocoCache.set(key, existingCache);
} catch {}
}
// set meta // set meta
return await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.MODELS, MetaTable.MODELS,
{ prepareForDb({
meta: typeof meta === 'object' ? JSON.stringify(meta) : meta, meta,
}, }),
tableId, tableId,
); );
await NocoCache.update(
`${CacheScope.MODEL}:${tableId}`,
prepareForResponse({
meta,
}),
);
return res;
} }
static async getNonDefaultViewsCountAndReset( static async getNonDefaultViewsCountAndReset(

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

@ -86,17 +86,8 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType {
role: string, role: string,
body: { disabled: any }, body: { disabled: any },
) { ) {
// get existing cache
const key = `${CacheScope.MODEL_ROLE_VISIBILITY}:${fk_view_id}:${role}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.disabled = body.disabled;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
return await Noco.ncMeta.metaUpdate( const res = await Noco.ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.MODEL_ROLE_VISIBILITY, MetaTable.MODEL_ROLE_VISIBILITY,
@ -108,6 +99,15 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType {
role, role,
}, },
); );
await NocoCache.update(
`${CacheScope.MODEL_ROLE_VISIBILITY}:${fk_view_id}:${role}`,
{
disabled: body.disabled,
},
);
return res;
} }
async delete() { async delete() {

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

@ -148,16 +148,6 @@ export default class Sort {
} }
public static async update(sortId, body, ncMeta = Noco.ncMeta) { public static async update(sortId, body, ncMeta = Noco.ncMeta) {
// get existing cache
const key = `${CacheScope.SORT}:${sortId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update fk_column_id & direction
o.fk_column_id = body.fk_column_id;
o.direction = body.direction;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
const res = await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
null, null,
@ -170,6 +160,11 @@ export default class Sort {
sortId, sortId,
); );
await NocoCache.update(`${CacheScope.SORT}:${sortId}`, {
fk_column_id: body.fk_column_id,
direction: body.direction,
});
// on update, delete any optimised single query cache // on update, delete any optimised single query cache
{ {
const sort = await this.get(sortId, ncMeta); const sort = await this.get(sortId, ncMeta);

28
packages/nocodb/src/models/Source.ts

@ -478,15 +478,7 @@ export default class Source implements SourceType {
if (!this.erd_uuid) { if (!this.erd_uuid) {
const uuid = uuidv4(); const uuid = uuidv4();
this.erd_uuid = uuid; this.erd_uuid = uuid;
// get existing cache
const key = `${CacheScope.BASE}:${this.id}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.erd_uuid = uuid;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
@ -497,6 +489,10 @@ export default class Source implements SourceType {
}, },
this.id, this.id,
); );
await NocoCache.update(`${CacheScope.BASE}:${this.id}`, {
erd_uuid: this.erd_uuid,
});
} }
return this; return this;
} }
@ -504,15 +500,7 @@ export default class Source implements SourceType {
async disableShareErd(ncMeta = Noco.ncMeta) { async disableShareErd(ncMeta = Noco.ncMeta) {
if (this.erd_uuid) { if (this.erd_uuid) {
this.erd_uuid = null; this.erd_uuid = null;
// get existing cache
const key = `${CacheScope.BASE}:${this.id}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.erd_uuid = null;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
@ -523,6 +511,10 @@ export default class Source implements SourceType {
}, },
this.id, this.id,
); );
await NocoCache.update(`${CacheScope.BASE}:${this.id}`, {
erd_uuid: this.erd_uuid,
});
} }
return this; return this;
} }

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

@ -26,7 +26,12 @@ import {
MetaTable, MetaTable,
} from '~/utils/globals'; } from '~/utils/globals';
import Noco from '~/Noco'; import Noco from '~/Noco';
import { parseMetaProp, stringifyMetaProp } from '~/utils/modelUtils'; import {
parseMetaProp,
prepareForDb,
prepareForResponse,
stringifyMetaProp,
} from '~/utils/modelUtils';
const { v4: uuidv4 } = require('uuid'); const { v4: uuidv4 } = require('uuid');
@ -981,15 +986,7 @@ export default class View implements ViewType {
if (!view.uuid) { if (!view.uuid) {
const uuid = uuidv4(); const uuid = uuidv4();
view.uuid = uuid; view.uuid = uuid;
// get existing cache
const key = `${CacheScope.VIEW}:${view.id}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.uuid = uuid;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
@ -1000,32 +997,35 @@ export default class View implements ViewType {
}, },
viewId, viewId,
); );
await NocoCache.update(`${CacheScope.VIEW}:${view.id}`, {
uuid: view.uuid,
});
} }
if (!view.meta || !('allowCSVDownload' in view.meta)) { if (!view.meta || !('allowCSVDownload' in view.meta)) {
const defaultMeta = { const defaultMeta = {
...(view.meta ?? {}), ...(view.meta ?? {}),
allowCSVDownload: true, allowCSVDownload: true,
}; };
// get existing cache view.meta = defaultMeta;
const key = `${CacheScope.VIEW}:${view.id}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.meta = defaultMeta;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.VIEWS, MetaTable.VIEWS,
{ prepareForDb({
meta: JSON.stringify(defaultMeta), meta: defaultMeta,
}, }),
viewId, viewId,
); );
view.meta = defaultMeta;
await NocoCache.update(
`${CacheScope.VIEW}:${view.id}`,
prepareForResponse({
meta: defaultMeta,
}),
);
} }
return view; return view;
} }
@ -1035,15 +1035,6 @@ export default class View implements ViewType {
{ password }: { password: string }, { password }: { password: string },
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
// get existing cache
const key = `${CacheScope.VIEW}:${viewId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.password = password;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
@ -1054,18 +1045,13 @@ export default class View implements ViewType {
}, },
viewId, viewId,
); );
await NocoCache.update(`${CacheScope.VIEW}:${viewId}`, {
password,
});
} }
static async sharedViewDelete(viewId, ncMeta = Noco.ncMeta) { static async sharedViewDelete(viewId, ncMeta = Noco.ncMeta) {
// get existing cache
const key = `${CacheScope.VIEW}:${viewId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.uuid = null;
// set cache
await NocoCache.set(key, o);
}
// set meta // set meta
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
null, null,
@ -1076,6 +1062,10 @@ export default class View implements ViewType {
}, },
viewId, viewId,
); );
await NocoCache.update(`${CacheScope.VIEW}:${viewId}`, {
uuid: null,
});
} }
static async update( static async update(
@ -1101,37 +1091,33 @@ export default class View implements ViewType {
'uuid', 'uuid',
]); ]);
// get existing cache const oldView = await this.get(viewId, ncMeta);
const key = `${CacheScope.VIEW}:${viewId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); // set meta
let oldView = { ...o }; await ncMeta.metaUpdate(
if (o) { null,
// update data null,
o = { MetaTable.VIEWS,
...o, prepareForDb(updateObj),
...updateObj, viewId,
}; );
if (o.is_default) {
await NocoCache.set(`${CacheScope.VIEW}:${o.fk_model_id}:default`, o);
}
// set cache
await NocoCache.set(key, o);
} else {
oldView = await this.get(viewId);
}
// reset alias cache // reset alias cache
await NocoCache.del( await NocoCache.del(
`${CacheScope.VIEW}:${oldView.fk_model_id}:${oldView.title}`, `${CacheScope.VIEW}:${oldView.fk_model_id}:${oldView.title}`,
); );
// if meta data defined then stringify it await NocoCache.update(
if ('meta' in updateObj) { `${CacheScope.VIEW}:${viewId}`,
updateObj.meta = stringifyMetaProp(updateObj); prepareForResponse(updateObj),
} );
// set meta if (oldView.is_default) {
await ncMeta.metaUpdate(null, null, MetaTable.VIEWS, updateObj, viewId); await NocoCache.update(
`${CacheScope.VIEW}:${oldView.fk_model_id}:default`,
prepareForResponse(updateObj),
);
}
const view = await this.get(viewId); const view = await this.get(viewId);

27
packages/nocodb/src/utils/modelUtils.ts

@ -24,22 +24,37 @@ export function stringifyMetaProp(model: any, propName = 'meta'): string {
} }
} }
export function prepareForDb(model: any) { export function prepareForDb(model: any, props: string | string[] = 'meta') {
if (!model) return model; if (!model) return model;
if (model.meta) { if (typeof props === 'string') {
model.meta = stringifyMetaProp(model); props = [props];
} }
props.forEach((prop) => {
if (prop in model) {
model[prop] = stringifyMetaProp(model, prop);
}
});
return model; return model;
} }
export function prepareForResponse(model: any) { export function prepareForResponse(
model: any,
props: string | string[] = 'meta',
) {
if (!model) return model; if (!model) return model;
if (model.meta) { if (typeof props === 'string') {
model.meta = parseMetaProp(model); props = [props];
}
props.forEach((prop) => {
if (prop in model) {
model[prop] = parseMetaProp(model, prop);
} }
});
return model; return model;
} }

Loading…
Cancel
Save