Skip to content

Commit

Permalink
Remove cache for project policy updating
Browse files Browse the repository at this point in the history
1. Fixes #19065

Signed-off-by: AllForNothing <[email protected]>
  • Loading branch information
AllForNothing committed Aug 1, 2023
1 parent 5e130bd commit b1c0b77
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
Expand Down
25 changes: 24 additions & 1 deletion src/portal/src/app/shared/services/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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];
}
Expand Down

0 comments on commit b1c0b77

Please sign in to comment.