Browse Source

fix: pass ncMeta ref wherever missing

pull/7777/head
Pranav C 9 months ago
parent
commit
d8db7d63e4
  1. 5
      packages/nocodb/src/helpers/formulaHelpers.ts
  2. 2
      packages/nocodb/src/models/CalendarViewColumn.ts
  3. 33
      packages/nocodb/src/models/Column.ts
  4. 8
      packages/nocodb/src/models/Filter.ts
  5. 2
      packages/nocodb/src/models/GalleryViewColumn.ts
  6. 4
      packages/nocodb/src/models/GridViewColumn.ts
  7. 4
      packages/nocodb/src/models/Model.ts
  8. 8
      packages/nocodb/src/models/Sort.ts
  9. 42
      packages/nocodb/src/models/View.ts

5
packages/nocodb/src/helpers/formulaHelpers.ts

@ -2,6 +2,7 @@ import jsep from 'jsep';
import { UITypes } from 'nocodb-sdk'; import { UITypes } from 'nocodb-sdk';
import type FormulaColumn from '../models/FormulaColumn'; import type FormulaColumn from '../models/FormulaColumn';
import type { Column } from '~/models'; import type { Column } from '~/models';
import Noco from "~/Noco";
export async function getFormulasReferredTheColumn({ export async function getFormulasReferredTheColumn({
column, column,
@ -9,7 +10,7 @@ export async function getFormulasReferredTheColumn({
}: { }: {
column: Column; column: Column;
columns: Column[]; columns: Column[];
}): Promise<Column[]> { }, ncMeta = Noco.ncMeta): Promise<Column[]> {
const fn = (pt) => { const fn = (pt) => {
if (pt.type === 'CallExpression') { if (pt.type === 'CallExpression') {
return pt.arguments.some((arg) => fn(arg)); return pt.arguments.some((arg) => fn(arg));
@ -25,7 +26,7 @@ export async function getFormulasReferredTheColumn({
const columns = await columnsPromise; const columns = await columnsPromise;
if (c.uidt !== UITypes.Formula) return columns; if (c.uidt !== UITypes.Formula) return columns;
const formula = await c.getColOptions<FormulaColumn>(); const formula = await c.getColOptions<FormulaColumn>(ncMeta);
if (fn(jsep(formula.formula))) { if (fn(jsep(formula.formula))) {
columns.push(c); columns.push(c);

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

@ -93,7 +93,7 @@ export default class CalendarViewColumn {
{ {
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], ncMeta);
} }
return this.get(id, ncMeta).then(async (viewColumn) => { return this.get(id, ncMeta).then(async (viewColumn) => {

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

@ -216,7 +216,7 @@ export default class Column<T = any> implements ColumnType {
ncMeta, ncMeta,
); );
await View.clearSingleQueryCache(column.fk_model_id); await View.clearSingleQueryCache(column.fk_model_id, null, ncMeta);
return col; return col;
} }
@ -914,7 +914,7 @@ export default class Column<T = any> implements ColumnType {
// on column delete, delete any optimised single query cache // on column delete, delete any optimised single query cache
{ {
await View.clearSingleQueryCache(col.fk_model_id); await View.clearSingleQueryCache(col.fk_model_id, null, ncMeta);
} }
} }
@ -1074,11 +1074,16 @@ export default class Column<T = any> implements ColumnType {
column.column_order.view_id column.column_order.view_id
) { ) {
const viewColumn = ( const viewColumn = (
await View.getColumns(column.column_order.view_id) await View.getColumns(column.column_order.view_id, ncMeta)
).find((col) => col.fk_column_id === column.id); ).find((col) => col.fk_column_id === column.id);
await View.updateColumn(column.column_order.view_id, viewColumn.id, { await View.updateColumn(
column.column_order.view_id,
viewColumn.id,
{
order: column.column_order.order, order: column.column_order.order,
}); },
ncMeta,
);
} }
// set meta // set meta
@ -1098,16 +1103,22 @@ export default class Column<T = any> implements ColumnType {
await this.insertColOption(column, colId, ncMeta); await this.insertColOption(column, colId, ncMeta);
// on column update, delete any optimised single query cache // on column update, delete any optimised single query cache
await View.clearSingleQueryCache(oldCol.fk_model_id); await View.clearSingleQueryCache(oldCol.fk_model_id, null, ncMeta);
const updatedColumn = await Column.get({ colId }); const updatedColumn = await Column.get({ colId }, ncMeta);
if (!skipFormulaInvalidate) { if (!skipFormulaInvalidate) {
// invalidate formula parsed-tree in which current column is used // invalidate formula parsed-tree in which current column is used
// whenever a new request comes for that formula, it will be populated again // whenever a new request comes for that formula, it will be populated again
getFormulasReferredTheColumn({ getFormulasReferredTheColumn(
{
column: updatedColumn, column: updatedColumn,
columns: await Column.list({ fk_model_id: oldCol.fk_model_id }, ncMeta), columns: await Column.list(
}) { fk_model_id: oldCol.fk_model_id },
ncMeta,
),
},
ncMeta,
)
.then(async (formulas) => { .then(async (formulas) => {
for (const formula of formulas) { for (const formula of formulas) {
await FormulaColumn.update( await FormulaColumn.update(
@ -1146,7 +1157,7 @@ export default class Column<T = any> implements ColumnType {
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, null, ncMeta);
} }
public getValidators(): any { public getValidators(): any {

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

@ -213,7 +213,7 @@ export default class Filter implements FilterType {
if (filter.fk_view_id) { if (filter.fk_view_id) {
const view = await View.get(filter.fk_view_id, ncMeta); const view = await View.get(filter.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
} }
} }
@ -253,7 +253,7 @@ export default class Filter implements FilterType {
const view = await View.get(filter.fk_view_id, ncMeta); const view = await View.get(filter.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [ await View.clearSingleQueryCache(view.fk_model_id, [
{ id: filter.fk_view_id }, { id: filter.fk_view_id },
]); ], ncMeta);
} }
} }
@ -283,7 +283,7 @@ export default class Filter implements FilterType {
await View.clearSingleQueryCache(view.fk_model_id, [ await View.clearSingleQueryCache(view.fk_model_id, [
{ id: filter.fk_view_id }, { id: filter.fk_view_id },
]); ], ncMeta);
} }
} }
} }
@ -437,7 +437,7 @@ export default class Filter implements FilterType {
// on update delete any optimised single query cache // on update delete any optimised single query cache
{ {
const view = await View.get(viewId, ncMeta); const view = await View.get(viewId, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
} }
} }

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

@ -81,7 +81,7 @@ export default class GalleryViewColumn {
// 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], ncMeta);
} }
return this.get(id, ncMeta).then(async (viewColumn) => { return this.get(id, ncMeta).then(async (viewColumn) => {

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

@ -114,7 +114,7 @@ export default class GridViewColumn implements GridColumnType {
// 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], ncMeta);
} }
return this.get(id, ncMeta).then(async (viewColumn) => { return this.get(id, ncMeta).then(async (viewColumn) => {
@ -159,7 +159,7 @@ export default class GridViewColumn implements GridColumnType {
{ {
const gridCol = await this.get(columnId, ncMeta); const gridCol = await this.get(columnId, ncMeta);
const view = await View.get(gridCol.fk_view_id, ncMeta); const view = await View.get(gridCol.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
} }
return res; return res;

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

@ -677,7 +677,7 @@ export default class Model implements TableType {
]); ]);
// clear all the cached query under this model // clear all the cached query under this model
await View.clearSingleQueryCache(tableId); await View.clearSingleQueryCache(tableId, null, ncMeta);
// clear all the cached query under related models // clear all the cached query under related models
for (const col of await this.get(tableId).then((t) => t.getColumns())) { for (const col of await this.get(tableId).then((t) => t.getColumns())) {
@ -687,7 +687,7 @@ export default class Model implements TableType {
if (colOptions.fk_related_model_id === tableId) continue; if (colOptions.fk_related_model_id === tableId) continue;
await View.clearSingleQueryCache(colOptions.fk_related_model_id); await View.clearSingleQueryCache(colOptions.fk_related_model_id, null, ncMeta);
} }
return res; return res;

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

@ -37,7 +37,7 @@ export default class Sort {
// on delete, delete any optimised single query cache // on delete, delete any optimised single query cache
{ {
const view = await View.get(viewId, ncMeta); const view = await View.get(viewId, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
} }
} }
@ -95,7 +95,7 @@ export default class Sort {
// on insert, delete any optimised single query cache // on insert, delete any optimised single query cache
{ {
const view = await View.get(row.fk_view_id, ncMeta); const view = await View.get(row.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view],ncMeta);
} }
return this.get(row.id, ncMeta).then(async (sort) => { return this.get(row.id, ncMeta).then(async (sort) => {
@ -169,7 +169,7 @@ export default class Sort {
{ {
const sort = await this.get(sortId, ncMeta); const sort = await this.get(sortId, ncMeta);
const view = await View.get(sort.fk_view_id, ncMeta); const view = await View.get(sort.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
} }
return res; return res;
@ -188,7 +188,7 @@ export default class Sort {
// on delete, delete any optimised single query cache // on delete, delete any optimised single query cache
if (sort?.fk_view_id) { if (sort?.fk_view_id) {
const view = await View.get(sort.fk_view_id, ncMeta); const view = await View.get(sort.fk_view_id, ncMeta);
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
} }
} }

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

@ -878,7 +878,7 @@ export default class View implements ViewType {
await NocoCache.update(`${cacheScope}:${colId}`, updateObj); await NocoCache.update(`${cacheScope}:${colId}`, updateObj);
// on view column update, delete corresponding single query cache // on view column update, delete corresponding single query cache
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
return res; return res;
} }
@ -920,7 +920,7 @@ export default class View implements ViewType {
); );
// on view column update, delete any optimised single query cache // on view column update, delete any optimised single query cache
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
return { ...existingCol, ...colData }; return { ...existingCol, ...colData };
} else { } else {
@ -1137,7 +1137,7 @@ export default class View implements ViewType {
} }
// on update, delete any optimised single query cache // on update, delete any optimised single query cache
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
return view; return view;
} }
@ -1188,7 +1188,7 @@ export default class View implements ViewType {
]); ]);
// on update, delete any optimised single query cache // on update, delete any optimised single query cache
await View.clearSingleQueryCache(view.fk_model_id, [view]); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta);
await Model.getNonDefaultViewsCountAndReset( await Model.getNonDefaultViewsCountAndReset(
{ modelId: view.fk_model_id }, { modelId: view.fk_model_id },
@ -1472,37 +1472,11 @@ export default class View implements ViewType {
} }
public static async clearSingleQueryCache( public static async clearSingleQueryCache(
modelId: string, _modelId: string,
views?: { id?: string }[], _views?: { id?: string }[],
ncMeta = Noco.ncMeta, _ncMeta = Noco.ncMeta,
) { ) {
// get all views of the model // do nothing
let viewsList =
views || (await NocoCache.getList(CacheScope.VIEW, [modelId])).list;
if (!views && !viewsList?.length) {
viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, {
condition: {
fk_model_id: modelId,
},
});
}
const deleteKeys = [];
for (const view of viewsList) {
deleteKeys.push(
`${CacheScope.SINGLE_QUERY}:${modelId}:${view.id}:queries`,
`${CacheScope.SINGLE_QUERY}:${modelId}:${view.id}:read`,
);
}
deleteKeys.push(
`${CacheScope.SINGLE_QUERY}:${modelId}:default:queries`,
`${CacheScope.SINGLE_QUERY}:${modelId}:default:read`,
);
await NocoCache.del(deleteKeys);
} }
static async bulkColumnInsertToViews( static async bulkColumnInsertToViews(

Loading…
Cancel
Save