diff --git a/backend/LexBoxApi/GraphQL/ProjectMutations.cs b/backend/LexBoxApi/GraphQL/ProjectMutations.cs index ccdb9046e9..2f6df40394 100644 --- a/backend/LexBoxApi/GraphQL/ProjectMutations.cs +++ b/backend/LexBoxApi/GraphQL/ProjectMutations.cs @@ -355,6 +355,24 @@ public async Task> SetRetentionPolicy( return dbContext.Projects.Where(p => p.Id == input.ProjectId); } + [Error] + [Error] + [Error] + [UseMutationConvention] + [UseFirstOrDefault] + [UseProjection] + public async Task> UpdateProjectRepoSizeInKb(string code, + IPermissionService permissionService, + ProjectService projectService, + LexBoxDbContext dbContext) + { + var projectId = await projectService.LookupProjectId(code); + await permissionService.AssertCanViewProject(projectId); + if (projectId == default) throw NotFoundException.ForType(); + await projectService.UpdateRepoSizeInKb(code); + return dbContext.Projects.Where(p => p.Id == projectId); + } + [Error] [Error] [Error] diff --git a/backend/LexBoxApi/Services/ProjectService.cs b/backend/LexBoxApi/Services/ProjectService.cs index 9732b1f29f..298f9faffc 100644 --- a/backend/LexBoxApi/Services/ProjectService.cs +++ b/backend/LexBoxApi/Services/ProjectService.cs @@ -244,6 +244,16 @@ public async Task UpdateProjectMetadata(Project project) // Caller is responsible for caling dbContext.SaveChangesAsync() } + public async Task UpdateRepoSizeInKb(string projectCode) + { + var project = await dbContext.Projects.FirstOrDefaultAsync(p => p.Code == projectCode); + if (project is null) return null; + var size = await hgService.GetRepoSizeInKb(projectCode); + project.RepoSizeInKb = size; + await dbContext.SaveChangesAsync(); + return size; + } + public async Task ResetLexEntryCount(string projectCode) { var project = await dbContext.Projects diff --git a/frontend/schema.graphql b/frontend/schema.graphql index 06060b836c..ec15ec026a 100644 --- a/frontend/schema.graphql +++ b/frontend/schema.graphql @@ -256,6 +256,7 @@ type Mutation { changeProjectDescription(input: ChangeProjectDescriptionInput!): ChangeProjectDescriptionPayload! @cost(weight: "10") setProjectConfidentiality(input: SetProjectConfidentialityInput!): SetProjectConfidentialityPayload! @cost(weight: "10") setRetentionPolicy(input: SetRetentionPolicyInput!): SetRetentionPolicyPayload! @cost(weight: "10") + updateProjectRepoSizeInKb(input: UpdateProjectRepoSizeInKbInput!): UpdateProjectRepoSizeInKbPayload! @cost(weight: "10") updateProjectLexEntryCount(input: UpdateProjectLexEntryCountInput!): UpdateProjectLexEntryCountPayload! @cost(weight: "10") updateProjectLanguageList(input: UpdateProjectLanguageListInput!): UpdateProjectLanguageListPayload! @cost(weight: "10") updateLangProjectId(input: UpdateLangProjectIdInput!): UpdateLangProjectIdPayload! @cost(weight: "10") @@ -384,6 +385,7 @@ type Project { flexProjectMetadata: FlexProjectMetadata organizations: [Organization!]! lastCommit: DateTime + repoSizeInKb: Int deletedDate: DateTime resetStatus: ResetStatus! projectOrigin: ProjectMigrationStatus! @@ -512,6 +514,11 @@ type UpdateProjectLexEntryCountPayload { errors: [UpdateProjectLexEntryCountError!] } +type UpdateProjectRepoSizeInKbPayload { + project: Project + errors: [UpdateProjectRepoSizeInKbError!] +} + type User { email: String @authorize(policy: "AdminRequiredPolicy") emailVerified: Boolean! @authorize(policy: "AdminRequiredPolicy") @@ -619,6 +626,8 @@ union UpdateProjectLanguageListError = NotFoundError | DbError | UnauthorizedAcc union UpdateProjectLexEntryCountError = NotFoundError | DbError | UnauthorizedAccessError +union UpdateProjectRepoSizeInKbError = NotFoundError | DbError | UnauthorizedAccessError + input AddProjectMemberInput { projectId: UUID! usernameOrEmail: String @@ -930,6 +939,7 @@ input ProjectFilterInput { users: ListFilterInputTypeOfProjectUsersFilterInput organizations: ListFilterInputTypeOfOrganizationFilterInput lastCommit: DateTimeOperationFilterInput + repoSizeInKb: IntOperationFilterInput deletedDate: DateTimeOperationFilterInput resetStatus: ResetStatusOperationFilterInput projectOrigin: ProjectMigrationStatusOperationFilterInput @@ -964,6 +974,7 @@ input ProjectSortInput { isConfidential: SortEnumType @cost(weight: "10") flexProjectMetadata: FlexProjectMetadataSortInput @cost(weight: "10") lastCommit: SortEnumType @cost(weight: "10") + repoSizeInKb: SortEnumType @cost(weight: "10") deletedDate: SortEnumType @cost(weight: "10") resetStatus: SortEnumType @cost(weight: "10") projectOrigin: SortEnumType @cost(weight: "10") @@ -1093,6 +1104,10 @@ input UpdateProjectLexEntryCountInput { code: String! } +input UpdateProjectRepoSizeInKbInput { + code: String! +} + input UserFilterInput { and: [UserFilterInput!] or: [UserFilterInput!]