Browse Source

fix(api): resetting user project cache after project delete/create

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4426/head
Pranav C 2 years ago
parent
commit
fa97580a37
  1. 13
      packages/nocodb/src/lib/cache/RedisCacheMgr.ts
  2. 7
      packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts
  3. 9
      packages/nocodb/src/lib/models/ProjectUser.ts

13
packages/nocodb/src/lib/cache/RedisCacheMgr.ts vendored

@ -2,6 +2,7 @@ import debug from 'debug';
import CacheMgr from './CacheMgr';
import Redis from 'ioredis';
import { CacheDelDirection, CacheGetType, CacheScope } from '../utils/globals';
const log = debug('nc:cache');
export default class RedisCacheMgr extends CacheMgr {
@ -101,11 +102,15 @@ export default class RedisCacheMgr extends CacheMgr {
log(
`RedisCacheMgr::delAll: deleting all keys with pattern ${this.prefix}:${scope}:${pattern}`
);
await Promise.all(
keys.map(async (k) => {
await this.deepDel(scope, k, CacheDelDirection.CHILD_TO_PARENT);
})
);
return Promise.all(
keys.map(
async (k) =>
await this.deepDel(scope, k, CacheDelDirection.CHILD_TO_PARENT)
)
keys.map(async (k) => {
await this.del(k);
})
);
}

7
packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts vendored

@ -101,12 +101,17 @@ export default class RedisMockCacheMgr extends CacheMgr {
log(
`RedisMockCacheMgr::delAll: deleting all keys with pattern ${this.prefix}:${scope}:${pattern}`
);
return Promise.all(
await Promise.all(
keys.map(
async (k) =>
await this.deepDel(scope, k, CacheDelDirection.CHILD_TO_PARENT)
)
);
return Promise.all(
keys.map(async (k) => {
await this.del(k);
})
);
}
async getList(scope: string, subKeys: string[]): Promise<any[]> {

9
packages/nocodb/src/lib/models/ProjectUser.ts

@ -36,10 +36,10 @@ export default class ProjectUser {
true
);
await NocoCache.appendToList(
// reset all user projects cache
await NocoCache.delAll(
CacheScope.USER_PROJECT,
[projectUser.fk_user_id],
`${CacheScope.USER_PROJECT}:${projectUser.project_id}`
`${projectUser.fk_user_id}:*`
);
return this.get(project_id, fk_user_id, ncMeta);
@ -236,13 +236,10 @@ export default class ProjectUser {
`${MetaTable.PROJECT_USERS}.project_id`,
`${MetaTable.PROJECT}.id`
);
// if (!isSuperAdmin) {
this.andOn(
`${MetaTable.PROJECT_USERS}.fk_user_id`,
ncMeta.knex.raw('?', [userId])
);
// }
})
.where(function () {
this.where(`${MetaTable.PROJECT}.deleted`, false).orWhereNull(

Loading…
Cancel
Save