Browse Source

fix: cache update for models with meta

pull/7727/head
mertmit 9 months ago
parent
commit
2751c804e0
  1. 34
      packages/nocodb/src/models/CalendarView.ts
  2. 20
      packages/nocodb/src/models/Column.ts
  3. 12
      packages/nocodb/src/models/FormView.ts
  4. 8
      packages/nocodb/src/models/GalleryView.ts
  5. 12
      packages/nocodb/src/models/GridView.ts
  6. 12
      packages/nocodb/src/models/KanbanView.ts
  7. 12
      packages/nocodb/src/models/MapView.ts
  8. 18
      packages/nocodb/src/models/Source.ts
  9. 20
      packages/nocodb/src/utils/modelUtils.ts

34
packages/nocodb/src/models/CalendarView.ts

@ -2,9 +2,15 @@ import type { BoolType, MetaType } from 'nocodb-sdk';
import type { CalendarType } from 'nocodb-sdk';
import View from '~/models/View';
import { extractProps } from '~/helpers/extractProps';
import { prepareForDb, prepareForResponse } from '~/utils/modelUtils';
import NocoCache from '~/cache/NocoCache';
import Noco from '~/Noco';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
import {
CacheDelDirection,
CacheGetType,
CacheScope,
MetaTable,
} from '~/utils/globals';
import CalendarRange from '~/models/CalendarRange';
export default class CalendarView implements CalendarType {
@ -87,17 +93,12 @@ export default class CalendarView implements CalendarType {
) {
const updateObj = extractProps(body, ['fk_cover_image_col_id', 'meta']);
if (updateObj.meta && typeof updateObj.meta === 'object') {
updateObj.meta = JSON.stringify(updateObj.meta ?? {});
}
await NocoCache.update(
if (body.calendar_range) {
// if calendar range is updated, delete cache
await NocoCache.deepDel(
`${CacheScope.CALENDAR_VIEW}:${calendarId}`,
updateObj,
CacheDelDirection.CHILD_TO_PARENT,
);
if (body.calendar_range) {
await NocoCache.del(`${CacheScope.CALENDAR_VIEW}:${calendarId}`);
await ncMeta.metaDelete(
null,
null,
@ -116,15 +117,24 @@ export default class CalendarView implements CalendarType {
}),
);
}
// update meta
return await ncMeta.metaUpdate(
const res = await ncMeta.metaUpdate(
null,
null,
MetaTable.CALENDAR_VIEW,
updateObj,
prepareForDb(updateObj),
{
fk_view_id: calendarId,
},
);
// update cache
await NocoCache.update(
`${CacheScope.CALENDAR_VIEW}:${calendarId}`,
prepareForResponse(updateObj),
);
return res;
}
}

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

@ -28,7 +28,12 @@ import {
MetaTable,
} from '~/utils/globals';
import NocoCache from '~/cache/NocoCache';
import { parseMetaProp, stringifyMetaProp } from '~/utils/modelUtils';
import {
parseMetaProp,
prepareForDb,
prepareForResponse,
stringifyMetaProp,
} from '~/utils/modelUtils';
import { getFormulasReferredTheColumn } from '~/helpers/formulaHelpers';
const selectColors = [
@ -1089,17 +1094,14 @@ export default class Column<T = any> implements ColumnType {
null,
null,
MetaTable.COLUMNS,
{
...updateObj,
meta:
updateObj.meta && typeof updateObj.meta === 'object'
? JSON.stringify(updateObj.meta)
: updateObj.meta,
},
prepareForDb(updateObj),
colId,
);
await NocoCache.update(`${CacheScope.COLUMN}:${colId}`, updateObj);
await NocoCache.update(
`${CacheScope.COLUMN}:${colId}`,
prepareForResponse(updateObj),
);
await this.insertColOption(column, colId, ncMeta);

12
packages/nocodb/src/models/FormView.ts

@ -7,6 +7,7 @@ import NocoCache from '~/cache/NocoCache';
import Noco from '~/Noco';
import { deserializeJSON, serializeJSON } from '~/utils/serialize';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
import { prepareForDb, prepareForResponse } from '~/utils/modelUtils';
export default class FormView implements FormType {
show: BoolType;
@ -102,22 +103,21 @@ export default class FormView implements FormType {
'meta',
]);
if (updateObj.meta) {
updateObj.meta = serializeJSON(updateObj.meta);
}
// update meta
const res = await ncMeta.metaUpdate(
null,
null,
MetaTable.FORM_VIEW,
updateObj,
prepareForDb(updateObj),
{
fk_view_id: formId,
},
);
await NocoCache.update(`${CacheScope.FORM_VIEW}:${formId}`, updateObj);
await NocoCache.update(
`${CacheScope.FORM_VIEW}:${formId}`,
prepareForResponse(updateObj),
);
return res;
}

8
packages/nocodb/src/models/GalleryView.ts

@ -10,6 +10,7 @@ import Noco from '~/Noco';
import NocoCache from '~/cache/NocoCache';
import { extractProps } from '~/helpers/extractProps';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
import { prepareForDb, prepareForResponse } from '~/utils/modelUtils';
export default class GalleryView implements GalleryType {
fk_view_id?: string;
@ -99,16 +100,13 @@ export default class GalleryView implements GalleryType {
ncMeta = Noco.ncMeta,
) {
const updateObj = extractProps(body, ['fk_cover_image_col_id', 'meta']);
if (updateObj.meta && typeof updateObj.meta === 'object') {
updateObj.meta = JSON.stringify(updateObj.meta ?? {});
}
// update meta
const res = await ncMeta.metaUpdate(
null,
null,
MetaTable.GALLERY_VIEW,
updateObj,
prepareForDb(updateObj),
{
fk_view_id: galleryId,
},
@ -116,7 +114,7 @@ export default class GalleryView implements GalleryType {
await NocoCache.update(
`${CacheScope.GALLERY_VIEW}:${galleryId}`,
updateObj,
prepareForResponse(updateObj),
);
return res;

12
packages/nocodb/src/models/GridView.ts

@ -5,6 +5,7 @@ import Noco from '~/Noco';
import NocoCache from '~/cache/NocoCache';
import { extractProps } from '~/helpers/extractProps';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
import { prepareForDb, prepareForResponse } from '~/utils/modelUtils';
export default class GridView implements GridType {
fk_view_id: string;
@ -70,22 +71,21 @@ export default class GridView implements GridType {
) {
const updateObj = extractProps(body, ['row_height', 'meta']);
if (updateObj.meta && typeof updateObj.meta === 'object') {
updateObj.meta = JSON.stringify(updateObj.meta ?? {});
}
// update meta
const res = await ncMeta.metaUpdate(
null,
null,
MetaTable.GRID_VIEW,
updateObj,
prepareForDb(updateObj),
{
fk_view_id: viewId,
},
);
await NocoCache.update(`${CacheScope.GRID_VIEW}:${viewId}`, updateObj);
await NocoCache.update(
`${CacheScope.GRID_VIEW}:${viewId}`,
prepareForResponse(res),
);
return res;
}

12
packages/nocodb/src/models/KanbanView.ts

@ -5,6 +5,7 @@ import Noco from '~/Noco';
import NocoCache from '~/cache/NocoCache';
import { extractProps } from '~/helpers/extractProps';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
import { prepareForDb, prepareForResponse } from '~/utils/modelUtils';
export default class KanbanView implements KanbanType {
fk_view_id: string;
@ -105,22 +106,21 @@ export default class KanbanView implements KanbanType {
'meta',
]);
if (updateObj.meta && typeof updateObj.meta === 'object') {
updateObj.meta = JSON.stringify(updateObj.meta ?? {});
}
// update meta
const res = await ncMeta.metaUpdate(
null,
null,
MetaTable.KANBAN_VIEW,
updateObj,
prepareForDb(updateObj),
{
fk_view_id: kanbanId,
},
);
await NocoCache.update(`${CacheScope.KANBAN_VIEW}:${kanbanId}`, updateObj);
await NocoCache.update(
`${CacheScope.KANBAN_VIEW}:${kanbanId}`,
prepareForResponse(updateObj),
);
return res;
}

12
packages/nocodb/src/models/MapView.ts

@ -6,6 +6,7 @@ import { extractProps } from '~/helpers/extractProps';
import NocoCache from '~/cache/NocoCache';
import Noco from '~/Noco';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
import { prepareForDb, prepareForResponse } from '~/utils/modelUtils';
export default class MapView implements MapType {
fk_view_id: string;
@ -72,10 +73,6 @@ export default class MapView implements MapType {
) {
const updateObj = extractProps(body, ['fk_geo_data_col_id', 'meta']);
if (updateObj.meta && typeof updateObj.meta === 'object') {
updateObj.meta = JSON.stringify(updateObj.meta ?? {});
}
if (body.fk_geo_data_col_id != null) {
const mapViewColumns = await MapViewColumn.list(mapId);
const mapViewMappedByColumn = mapViewColumns.find(
@ -92,13 +89,16 @@ export default class MapView implements MapType {
null,
null,
MetaTable.MAP_VIEW,
updateObj,
prepareForDb(updateObj),
{
fk_view_id: mapId,
},
);
await NocoCache.update(`${CacheScope.MAP_VIEW}:${mapId}`, updateObj);
await NocoCache.update(
`${CacheScope.MAP_VIEW}:${mapId}`,
prepareForResponse(updateObj),
);
return res;
}

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

@ -17,7 +17,12 @@ import Noco from '~/Noco';
import { extractProps } from '~/helpers/extractProps';
import { NcError } from '~/helpers/catchError';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { parseMetaProp, stringifyMetaProp } from '~/utils/modelUtils';
import {
parseMetaProp,
prepareForDb,
prepareForResponse,
stringifyMetaProp,
} from '~/utils/modelUtils';
// todo: hide credentials
export default class Source implements SourceType {
@ -130,10 +135,6 @@ export default class Source implements SourceType {
).toString();
}
if ('meta' in updateObj) {
updateObj.meta = stringifyMetaProp(updateObj);
}
// type property is undefined even if not provided
if (!updateObj.type) {
updateObj.type = oldBase.type;
@ -143,11 +144,14 @@ export default class Source implements SourceType {
source.baseId,
null,
MetaTable.BASES,
updateObj,
prepareForDb(updateObj),
oldBase.id,
);
await NocoCache.update(`${CacheScope.BASE}:${sourceId}`, updateObj);
await NocoCache.update(
`${CacheScope.BASE}:${sourceId}`,
prepareForResponse(updateObj),
);
// call before reorder to update cache
const returnBase = await this.get(oldBase.id, false, ncMeta);

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

@ -23,3 +23,23 @@ export function stringifyMetaProp(model: any, propName = 'meta'): string {
return '{}';
}
}
export function prepareForDb(model: any) {
if (!model) return model;
if (model.meta) {
model.meta = stringifyMetaProp(model);
}
return model;
}
export function prepareForResponse(model: any) {
if (!model) return model;
if (model.meta) {
model.meta = parseMetaProp(model);
}
return model;
}

Loading…
Cancel
Save