Skip to content

Commit

Permalink
Invalidate projectCode-projectId cache on deletion
Browse files Browse the repository at this point in the history
Otherwise when you delete a project and create a new one with the same
code, it will return errors from GraphQL queries until the project code
to project ID cache expires, because it will still be trying to use the
GUID of the old project that was deleted.
  • Loading branch information
rmunn committed Jul 8, 2024
1 parent e99ed21 commit da26fa2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ public async Task<IQueryable<Project>> SoftDeleteProject(
await dbContext.SaveChangesAsync();
await hgService.SoftDeleteRepo(projectCode, timestamp);
projectService.InvalidateProjectConfidentialityCache(projectId);
projectService.InvalidateProjectCodeCache(projectCode);
await transaction.CommitAsync();

return dbContext.Projects.Where(p => p.Id == projectId);
Expand Down
6 changes: 6 additions & 0 deletions backend/LexBoxApi/Services/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public async ValueTask<Guid> LookupProjectId(string projectCode)
return projectId;
}

public void InvalidateProjectCodeCache(string projectCode)
{
try { memoryCache.Remove($"ProjectIdForCode:{projectCode}"); }
catch (Exception) { }; // Never allow this to throw
}

public async Task<BackupExecutor?> BackupProject(string code)
{
var exists = await dbContext.Projects.Where(p => p.Code == code)
Expand Down

0 comments on commit da26fa2

Please sign in to comment.