Browse Source

fix: cache update for models with meta

pull/7727/head
mertmit 9 months ago
parent
commit
2751c804e0
  1. 36
      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

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

@ -2,9 +2,15 @@ import type { BoolType, MetaType } from 'nocodb-sdk';
import type { CalendarType } from 'nocodb-sdk'; import type { CalendarType } from 'nocodb-sdk';
import View from '~/models/View'; import View from '~/models/View';
import { extractProps } from '~/helpers/extractProps'; import { extractProps } from '~/helpers/extractProps';
import { prepareForDb, prepareForResponse } from '~/utils/modelUtils';
import NocoCache from '~/cache/NocoCache'; import NocoCache from '~/cache/NocoCache';
import Noco from '~/Noco'; import Noco from '~/Noco';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals'; import {
CacheDelDirection,
CacheGetType,
CacheScope,
MetaTable,
} from '~/utils/globals';
import CalendarRange from '~/models/CalendarRange'; import CalendarRange from '~/models/CalendarRange';
export default class CalendarView implements CalendarType { 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']); 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(
`${CacheScope.CALENDAR_VIEW}:${calendarId}`,
updateObj,
);
if (body.calendar_range) { if (body.calendar_range) {
await NocoCache.del(`${CacheScope.CALENDAR_VIEW}:${calendarId}`); // if calendar range is updated, delete cache
await NocoCache.deepDel(
`${CacheScope.CALENDAR_VIEW}:${calendarId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await ncMeta.metaDelete( await ncMeta.metaDelete(
null, null,
null, null,
@ -116,15 +117,24 @@ export default class CalendarView implements CalendarType {
}), }),
); );
} }
// update meta // update meta
return await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.CALENDAR_VIEW, MetaTable.CALENDAR_VIEW,
updateObj, prepareForDb(updateObj),
{ {
fk_view_id: calendarId, 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, MetaTable,
} from '~/utils/globals'; } from '~/utils/globals';
import NocoCache from '~/cache/NocoCache'; import NocoCache from '~/cache/NocoCache';
import { parseMetaProp, stringifyMetaProp } from '~/utils/modelUtils'; import {
parseMetaProp,
prepareForDb,
prepareForResponse,
stringifyMetaProp,
} from '~/utils/modelUtils';
import { getFormulasReferredTheColumn } from '~/helpers/formulaHelpers'; import { getFormulasReferredTheColumn } from '~/helpers/formulaHelpers';
const selectColors = [ const selectColors = [
@ -1089,17 +1094,14 @@ export default class Column<T = any> implements ColumnType {
null, null,
null, null,
MetaTable.COLUMNS, MetaTable.COLUMNS,
{ prepareForDb(updateObj),
...updateObj,
meta:
updateObj.meta && typeof updateObj.meta === 'object'
? JSON.stringify(updateObj.meta)
: updateObj.meta,
},
colId, colId,
); );
await NocoCache.update(`${CacheScope.COLUMN}:${colId}`, updateObj); await NocoCache.update(
`${CacheScope.COLUMN}:${colId}`,
prepareForResponse(updateObj),
);
await this.insertColOption(column, colId, ncMeta); 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 Noco from '~/Noco';
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 FormView implements FormType { export default class FormView implements FormType {
show: BoolType; show: BoolType;
@ -102,22 +103,21 @@ export default class FormView implements FormType {
'meta', 'meta',
]); ]);
if (updateObj.meta) {
updateObj.meta = serializeJSON(updateObj.meta);
}
// update meta // update meta
const res = await ncMeta.metaUpdate( const res = await ncMeta.metaUpdate(
null, null,
null, null,
MetaTable.FORM_VIEW, MetaTable.FORM_VIEW,
updateObj, prepareForDb(updateObj),
{ {
fk_view_id: formId, fk_view_id: formId,
}, },
); );
await NocoCache.update(`${CacheScope.FORM_VIEW}:${formId}`, updateObj); await NocoCache.update(
`${CacheScope.FORM_VIEW}:${formId}`,
prepareForResponse(updateObj),
);
return res; return res;
} }

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

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

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

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

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

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

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

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

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

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