Browse Source

Merge pull request #9506 from nocodb/nc-fix/datasource-change

fix: Query cache on source update
pull/9519/head
Pranav C 2 months ago committed by GitHub
parent
commit
9c821eb506
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      packages/nocodb/src/controllers/sources.controller.ts
  2. 24
      packages/nocodb/src/models/Source.ts
  3. 4
      packages/nocodb/src/services/sources.service.ts

9
packages/nocodb/src/controllers/sources.controller.ts

@ -37,6 +37,7 @@ export class SourcesController {
if (source.isMeta()) {
source.config = undefined;
}
source.integration_config = undefined;
return source;
}
@ -60,6 +61,9 @@ export class SourcesController {
req,
});
source.config = undefined;
source.integration_config = undefined;
return source;
}
@ -77,9 +81,8 @@ export class SourcesController {
});
for (const source of sources) {
if (source.isMeta()) {
source.config = undefined;
}
source.config = undefined;
source.integration_config = undefined;
}
return new PagedResponseImpl(sources, {

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

@ -25,6 +25,7 @@ import {
import { JobsRedis } from '~/modules/jobs/redis/jobs-redis';
import { InstanceCommands } from '~/interface/Jobs';
import { deepMerge, partialExtract } from '~/utils';
import View from '~/models/View';
export default class Source implements SourceType {
id?: string;
@ -201,6 +202,11 @@ export default class Source implements SourceType {
prepareForResponse(updateObj),
);
// trigger cache clear and don't wait
this.updateRelatedCaches(context, sourceId, ncMeta).catch((e) => {
console.error(e);
});
if (JobsRedis.available) {
await JobsRedis.emitWorkerCommand(InstanceCommands.RELEASE, sourceId);
await JobsRedis.emitPrimaryCommand(InstanceCommands.RELEASE, sourceId);
@ -566,4 +572,22 @@ export default class Source implements SourceType {
`${MetaTable.INTEGRATIONS}.id`,
);
}
private static async updateRelatedCaches(
context: NcContext,
sourceId: string,
ncMeta = Noco.ncMeta,
) {
// get models
const models = await Model.list(
context,
{ source_id: sourceId, base_id: context.base_id },
ncMeta,
);
// clear single query caches for models
for (const model of models) {
await View.clearSingleQueryCache(context, model.id, null, ncMeta);
}
}
}

4
packages/nocodb/src/services/sources.service.ts

@ -21,6 +21,10 @@ export class SourcesService {
async baseGetWithConfig(context: NcContext, param: { sourceId: any }) {
const source = await Source.get(context, param.sourceId);
if (!source) {
NcError.sourceNotFound(param.sourceId);
}
source.config = await source.getSourceConfig();
return source;

Loading…
Cancel
Save