Remove cache for project policy updating (#19068)

1. Fixes #19065

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
Shijun Sun 2023-08-01 15:31:32 +08:00 committed by GitHub
parent 5e130bd06c
commit 28e6a99eb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 4 deletions

View File

@ -42,7 +42,7 @@ export class ArtifactDetailRoutingResolverService {
const projectId: string = route.params['id'];
const repositoryName: string = route.params['repo'];
const artifactDigest: string = route.params['digest'];
return this.projectService.getProject(projectId).pipe(
return this.projectService.getProjectFromCache(projectId).pipe(
mergeMap((project: Project) => {
return forkJoin([
this.artifactService.getArtifact({

View File

@ -43,7 +43,7 @@ export class ProjectRoutingResolver {
if (!projectId) {
projectId = route.queryParams['project_id'];
}
return this.projectService.getProject(projectId).pipe(
return this.projectService.getProjectFromCache(projectId).pipe(
map(
(project: Project) => {
if (project) {

View File

@ -72,7 +72,7 @@ export class MemberGuard {
route: ActivatedRouteSnapshot
): Observable<boolean> {
// Note: current user will have the permission to visit the project when the user can get response from GET /projects/:id API.
return this.projectService.getProject(projectId).pipe(
return this.projectService.getProjectFromCache(projectId).pipe(
map(() => {
return true;
}),

View File

@ -31,6 +31,19 @@ export abstract class ProjectService {
*/
abstract getProject(projectId: number | string): Observable<Project>;
/**
* Get info about a specific Project from cache, if no cache, get it from the back end then store it in cache.
*
* @abstract
* ** deprecated param {string|number} [projectId]
* returns {(Observable<Project> )}
*
* @memberOf ProjectService
*/
abstract getProjectFromCache(
projectId: number | string
): Observable<Project>;
/**
* Update the specified project.
*
@ -95,12 +108,22 @@ export class ProjectDefaultService extends ProjectService {
constructor(private http: HttpClient) {
super();
}
@CacheObservable({ maxAge: 1000 * 60 })
public getProject(projectId: number | string): Observable<Project> {
if (!projectId) {
return observableThrowError('Bad argument');
}
let baseUrl: string = CURRENT_BASE_HREF + '/projects';
return this.http
.get<Project>(`${baseUrl}/${projectId}`, HTTP_GET_OPTIONS)
.pipe(catchError(error => observableThrowError(error)));
}
@CacheObservable({ maxAge: 1000 * 30 })
public getProjectFromCache(
projectId: number | string
): Observable<Project> {
const baseUrl: string = CURRENT_BASE_HREF + '/projects';
if (this._sharedProjectObservableMap[projectId]) {
return this._sharedProjectObservableMap[projectId];
}