mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-25 19:56:09 +01:00
Remove cache for project policy updating (#19068)
1. Fixes #19065 Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
parent
5e130bd06c
commit
28e6a99eb9
@ -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({
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}),
|
||||
|
@ -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];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user