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

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

@ -101,12 +101,17 @@ export default class RedisMockCacheMgr extends CacheMgr {
log( log(
`RedisMockCacheMgr::delAll: deleting all keys with pattern ${this.prefix}:${scope}:${pattern}` `RedisMockCacheMgr::delAll: deleting all keys with pattern ${this.prefix}:${scope}:${pattern}`
); );
return Promise.all( await Promise.all(
keys.map( keys.map(
async (k) => async (k) =>
await this.deepDel(scope, k, CacheDelDirection.CHILD_TO_PARENT) 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[]> { 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 true
); );
await NocoCache.appendToList( // reset all user projects cache
await NocoCache.delAll(
CacheScope.USER_PROJECT, CacheScope.USER_PROJECT,
[projectUser.fk_user_id], `${projectUser.fk_user_id}:*`
`${CacheScope.USER_PROJECT}:${projectUser.project_id}`
); );
return this.get(project_id, fk_user_id, ncMeta); return this.get(project_id, fk_user_id, ncMeta);
@ -236,13 +236,10 @@ export default class ProjectUser {
`${MetaTable.PROJECT_USERS}.project_id`, `${MetaTable.PROJECT_USERS}.project_id`,
`${MetaTable.PROJECT}.id` `${MetaTable.PROJECT}.id`
); );
// if (!isSuperAdmin) {
this.andOn( this.andOn(
`${MetaTable.PROJECT_USERS}.fk_user_id`, `${MetaTable.PROJECT_USERS}.fk_user_id`,
ncMeta.knex.raw('?', [userId]) ncMeta.knex.raw('?', [userId])
); );
// }
}) })
.where(function () { .where(function () {
this.where(`${MetaTable.PROJECT}.deleted`, false).orWhereNull( this.where(`${MetaTable.PROJECT}.deleted`, false).orWhereNull(

Loading…
Cancel
Save