Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cache for project policy updating #19068

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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