Browse Source

Merge pull request #7823 from nocodb/nc-fix/export-issue

fix: duplicate base/model
pull/7840/head
Raju Udava 5 months ago committed by GitHub
parent
commit
bc77419617
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 1
      packages/nocodb/src/helpers/PagedResponse.ts
  3. 6
      packages/nocodb/src/helpers/extractLimitAndOffset.ts
  4. 16
      packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts
  5. 2
      packages/nocodb/src/services/calendar-datas.service.ts
  6. 9
      packages/nocodb/src/services/datas.service.ts

12
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -318,14 +318,14 @@ class BaseModelSqlv2 {
sortArr?: Sort[]; sortArr?: Sort[];
sort?: string | string[]; sort?: string | string[];
fieldsSet?: Set<string>; fieldsSet?: Set<string>;
calendarLimitOverride?: number; limitOverride?: number;
} = {}, } = {},
options: { options: {
ignoreViewFilterAndSort?: boolean; ignoreViewFilterAndSort?: boolean;
ignorePagination?: boolean; ignorePagination?: boolean;
validateFormula?: boolean; validateFormula?: boolean;
throwErrorIfInvalidParams?: boolean; throwErrorIfInvalidParams?: boolean;
calendarLimitOverride?: number; limitOverride?: number;
} = {}, } = {},
): Promise<any> { ): Promise<any> {
const { const {
@ -333,7 +333,7 @@ class BaseModelSqlv2 {
ignorePagination = false, ignorePagination = false,
validateFormula = false, validateFormula = false,
throwErrorIfInvalidParams = false, throwErrorIfInvalidParams = false,
calendarLimitOverride, limitOverride,
} = options; } = options;
const { where, fields, ...rest } = this._getListArgs(args as any); const { where, fields, ...rest } = this._getListArgs(args as any);
@ -439,12 +439,12 @@ class BaseModelSqlv2 {
}); });
} }
// For calendar View, if calendarLimitOverride is provided, use it as limit for the query // if limitOverride is provided, use it as limit for the query (for internal usage eg. calendar, export)
if (!ignorePagination) { if (!ignorePagination) {
if (!calendarLimitOverride) { if (!limitOverride) {
applyPaginate(qb, rest); applyPaginate(qb, rest);
} else { } else {
applyPaginate(qb, { ...rest, limit: calendarLimitOverride }); applyPaginate(qb, { ...rest, limit: limitOverride });
} }
} }
const proto = await this.getProto(); const proto = await this.getProto();

1
packages/nocodb/src/helpers/PagedResponse.ts

@ -11,6 +11,7 @@ export class PagedResponseImpl<T> {
count?: number | string; count?: number | string;
l?: number; l?: number;
o?: number; o?: number;
limitOverride?: number;
} = {}, } = {},
additionalProps?: Record<string, any>, additionalProps?: Record<string, any>,
) { ) {

6
packages/nocodb/src/helpers/extractLimitAndOffset.ts

@ -15,6 +15,7 @@ export function extractLimitAndOffset(
offset?: number | string; offset?: number | string;
l?: number | string; l?: number | string;
o?: number | string; o?: number | string;
limitOverride?: number;
} = {}, } = {},
) { ) {
const obj: { const obj: {
@ -40,5 +41,10 @@ export function extractLimitAndOffset(
const offset = +(args.offset || args.o) || 0; const offset = +(args.offset || args.o) || 0;
obj.offset = Math.max(Number.isInteger(offset) ? offset : 0, 0); obj.offset = Math.max(Number.isInteger(offset) ? offset : 0, 0);
// override limit if provided
if (args.limitOverride) {
obj.limit = +args.limitOverride;
}
return obj; return obj;
} }

16
packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts

@ -13,6 +13,7 @@ import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { DatasService } from '~/services/datas.service'; import { DatasService } from '~/services/datas.service';
import { Base, Hook, Model, Source } from '~/models'; import { Base, Hook, Model, Source } from '~/models';
import { parseMetaProp } from '~/utils/modelUtils';
@Injectable() @Injectable()
export class ExportService { export class ExportService {
@ -220,10 +221,7 @@ export class ExportService {
break; break;
case 'meta': case 'meta':
if (view.type === ViewTypes.KANBAN) { if (view.type === ViewTypes.KANBAN) {
const meta = JSON.parse(view.view.meta as string) as Record< const meta = parseMetaProp(view.view) as Record<string, any>;
string,
any
>;
for (const [k, v] of Object.entries(meta)) { for (const [k, v] of Object.entries(meta)) {
const colId = idMap.get(k as string); const colId = idMap.get(k as string);
for (const op of v) { for (const op of v) {
@ -613,6 +611,7 @@ export class ExportService {
query: { limit, offset, fields }, query: { limit, offset, fields },
baseModel, baseModel,
ignoreViewFilterAndSort: true, ignoreViewFilterAndSort: true,
limitOverride: limit,
}) })
.then((result) => { .then((result) => {
try { try {
@ -634,7 +633,9 @@ export class ExportService {
offset + limit, offset + limit,
limit, limit,
fields, fields,
).then(resolve); )
.then(resolve)
.catch(reject);
} }
} catch (e) { } catch (e) {
reject(e); reject(e);
@ -663,6 +664,7 @@ export class ExportService {
query: { limit, offset, fields }, query: { limit, offset, fields },
baseModel, baseModel,
ignoreViewFilterAndSort: true, ignoreViewFilterAndSort: true,
limitOverride: limit,
}) })
.then((result) => { .then((result) => {
try { try {
@ -683,7 +685,9 @@ export class ExportService {
offset + limit, offset + limit,
limit, limit,
fields, fields,
).then(resolve); )
.then(resolve)
.catch(reject);
} }
} catch (e) { } catch (e) {
reject(e); reject(e);

2
packages/nocodb/src/services/calendar-datas.service.ts

@ -56,7 +56,7 @@ export class CalendarDatasService {
viewName: view.id, viewName: view.id,
baseName: model.base_id, baseName: model.base_id,
tableName: model.id, tableName: model.id,
calendarLimitOverride: 3000, // TODO: make this configurable in env limitOverride: 3000, // TODO: make this configurable in env
}); });
} }

9
packages/nocodb/src/services/datas.service.ts

@ -23,7 +23,7 @@ export class DatasService {
query: any; query: any;
disableOptimization?: boolean; disableOptimization?: boolean;
ignorePagination?: boolean; ignorePagination?: boolean;
calendarLimitOverride?: number; limitOverride?: number;
throwErrorIfInvalidParams?: boolean; throwErrorIfInvalidParams?: boolean;
}, },
) { ) {
@ -43,7 +43,7 @@ export class DatasService {
query: param.query, query: param.query,
throwErrorIfInvalidParams: true, throwErrorIfInvalidParams: true,
ignorePagination: param.ignorePagination, ignorePagination: param.ignorePagination,
calendarLimitOverride: param.calendarLimitOverride, limitOverride: param.limitOverride,
}); });
} }
@ -153,7 +153,7 @@ export class DatasService {
throwErrorIfInvalidParams?: boolean; throwErrorIfInvalidParams?: boolean;
ignoreViewFilterAndSort?: boolean; ignoreViewFilterAndSort?: boolean;
ignorePagination?: boolean; ignorePagination?: boolean;
calendarLimitOverride?: number; limitOverride?: number;
}) { }) {
const { model, view, query = {}, ignoreViewFilterAndSort = false } = param; const { model, view, query = {}, ignoreViewFilterAndSort = false } = param;
@ -193,7 +193,7 @@ export class DatasService {
ignoreViewFilterAndSort, ignoreViewFilterAndSort,
throwErrorIfInvalidParams: param.throwErrorIfInvalidParams, throwErrorIfInvalidParams: param.throwErrorIfInvalidParams,
ignorePagination: param.ignorePagination, ignorePagination: param.ignorePagination,
calendarLimitOverride: param.calendarLimitOverride, limitOverride: param.limitOverride,
}), }),
{}, {},
listArgs, listArgs,
@ -210,6 +210,7 @@ export class DatasService {
]); ]);
return new PagedResponseImpl(data, { return new PagedResponseImpl(data, {
...query, ...query,
...(param.limitOverride ? { limitOverride: param.limitOverride } : {}),
count, count,
}); });
} }

Loading…
Cancel
Save