From bebba7614e840b1b268656449d16b3be5a5d80e5 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Thu, 25 Jul 2024 11:16:20 +0700 Subject: [PATCH] Make "update where missing" calls HTTP POSTs again Instead of GraphQL calls, the batch "update X where missing" calls are more useful as HTTP POSTs so that they can be easily called from the Swagger UI. We're never going to call those from the frontend anyway. --- .../Controllers/ProjectController.cs | 42 ++++++++++++++ backend/LexBoxApi/GraphQL/ProjectMutations.cs | 58 ------------------- frontend/schema.graphql | 24 -------- 3 files changed, 42 insertions(+), 82 deletions(-) diff --git a/backend/LexBoxApi/Controllers/ProjectController.cs b/backend/LexBoxApi/Controllers/ProjectController.cs index c64f32645..838c61847 100644 --- a/backend/LexBoxApi/Controllers/ProjectController.cs +++ b/backend/LexBoxApi/Controllers/ProjectController.cs @@ -232,6 +232,48 @@ private async Task StreamHttpResponse(HttpContent hgResult) await hgResult.CopyToAsync(writer.AsStream()); } + [HttpPost("updateMissingLanguageList")] + public async Task> UpdateMissingLanguageList(int limit = 10) + { + var projects = lexBoxDbContext.Projects + .Include(p => p.FlexProjectMetadata) + .Where(p => p.Type == ProjectType.FLEx && p.LastCommit != null && p.FlexProjectMetadata!.WritingSystems == null) + .Take(limit) + .AsAsyncEnumerable(); + var codes = new List(limit); + await foreach (var project in projects) + { + codes.Add(project.Code); + project.FlexProjectMetadata ??= new FlexProjectMetadata(); + project.FlexProjectMetadata.WritingSystems = await hgService.GetProjectWritingSystems(project.Code); + } + + await lexBoxDbContext.SaveChangesAsync(); + + return Ok(codes); + } + + [HttpPost("updateMissingLangProjectId")] + public async Task> UpdateMissingLangProjectId(int limit = 10) + { + var projects = lexBoxDbContext.Projects + .Include(p => p.FlexProjectMetadata) + .Where(p => p.Type == ProjectType.FLEx && p.LastCommit != null && p.FlexProjectMetadata!.LangProjectId == null) + .Take(limit) + .AsAsyncEnumerable(); + var codes = new List(limit); + await foreach (var project in projects) + { + codes.Add(project.Code); + project.FlexProjectMetadata ??= new FlexProjectMetadata(); + project.FlexProjectMetadata.LangProjectId = await hgService.GetProjectIdOfFlexProject(project.Code); + } + + await lexBoxDbContext.SaveChangesAsync(); + + return Ok(codes); + } + [HttpPost("queueUpdateProjectMetadataTask")] public async Task QueueUpdateProjectMetadataTask(string projectCode) { diff --git a/backend/LexBoxApi/GraphQL/ProjectMutations.cs b/backend/LexBoxApi/GraphQL/ProjectMutations.cs index 85880abcc..7c3f8d62a 100644 --- a/backend/LexBoxApi/GraphQL/ProjectMutations.cs +++ b/backend/LexBoxApi/GraphQL/ProjectMutations.cs @@ -348,35 +348,6 @@ public async Task> UpdateProjectLanguageList(string code, return dbContext.Projects.Where(p => p.Id == projectId); } - [Error] - [Error] - [Error] - [UseMutationConvention] - [UseProjection] - [AdminRequired] - public async Task> UpdateProjectLanguageListWhereMissing( - [Service] IHgService hgService, - LexBoxDbContext dbContext, - int limit = 10) - { - var projects = dbContext.Projects - .Include(p => p.FlexProjectMetadata) - .Where(p => p.Type == ProjectType.FLEx && p.LastCommit != null && p.FlexProjectMetadata!.WritingSystems == null) - .Take(limit) - .AsAsyncEnumerable(); - var projectIds = new List(limit); - await foreach (var project in projects) - { - projectIds.Add(project.Id); - project.FlexProjectMetadata ??= new FlexProjectMetadata(); - project.FlexProjectMetadata.WritingSystems = await hgService.GetProjectWritingSystems(project.Code); - } - - await dbContext.SaveChangesAsync(); - - return dbContext.Projects.Where(p => projectIds.Contains(p.Id)); - } - [Error] [Error] [Error] @@ -397,35 +368,6 @@ public async Task> UpdateLangProjectId(string code, return dbContext.Projects.Where(p => p.Id == projectId); } - [Error] - [Error] - [Error] - [UseMutationConvention] - [UseProjection] - [AdminRequired] - public async Task> UpdateLangProjectIdWhereMissing( - [Service] IHgService hgService, - LexBoxDbContext dbContext, - int limit = 10) - { - var projects = dbContext.Projects - .Include(p => p.FlexProjectMetadata) - .Where(p => p.Type == ProjectType.FLEx && p.LastCommit != null && p.FlexProjectMetadata!.LangProjectId == null) - .Take(limit) - .AsAsyncEnumerable(); - var projectIds = new List(limit); - await foreach (var project in projects) - { - projectIds.Add(project.Id); - project.FlexProjectMetadata ??= new FlexProjectMetadata(); - project.FlexProjectMetadata.LangProjectId = await hgService.GetProjectIdOfFlexProject(project.Code); - } - - await dbContext.SaveChangesAsync(); - - return dbContext.Projects.Where(p => projectIds.Contains(p.Id)); - } - [Error] [Error] [UseMutationConvention] diff --git a/frontend/schema.graphql b/frontend/schema.graphql index b711398c9..567753484 100644 --- a/frontend/schema.graphql +++ b/frontend/schema.graphql @@ -239,9 +239,7 @@ type Mutation { setRetentionPolicy(input: SetRetentionPolicyInput!): SetRetentionPolicyPayload! updateProjectLexEntryCount(input: UpdateProjectLexEntryCountInput!): UpdateProjectLexEntryCountPayload! updateProjectLanguageList(input: UpdateProjectLanguageListInput!): UpdateProjectLanguageListPayload! - updateProjectLanguageListWhereMissing(input: UpdateProjectLanguageListWhereMissingInput!): UpdateProjectLanguageListWhereMissingPayload! @authorize(policy: "AdminRequiredPolicy") updateLangProjectId(input: UpdateLangProjectIdInput!): UpdateLangProjectIdPayload! - updateLangProjectIdWhereMissing(input: UpdateLangProjectIdWhereMissingInput!): UpdateLangProjectIdWhereMissingPayload! @authorize(policy: "AdminRequiredPolicy") leaveProject(input: LeaveProjectInput!): LeaveProjectPayload! removeProjectMember(input: RemoveProjectMemberInput!): RemoveProjectMemberPayload! deleteDraftProject(input: DeleteDraftProjectInput!): DeleteDraftProjectPayload! @authorize(policy: "AdminRequiredPolicy") @@ -476,21 +474,11 @@ type UpdateLangProjectIdPayload { errors: [UpdateLangProjectIdError!] } -type UpdateLangProjectIdWhereMissingPayload { - project: [Project!] - errors: [UpdateLangProjectIdWhereMissingError!] -} - type UpdateProjectLanguageListPayload { project: Project errors: [UpdateProjectLanguageListError!] } -type UpdateProjectLanguageListWhereMissingPayload { - project: [Project!] - errors: [UpdateProjectLanguageListWhereMissingError!] -} - type UpdateProjectLexEntryCountPayload { project: Project errors: [UpdateProjectLexEntryCountError!] @@ -582,12 +570,8 @@ union SoftDeleteProjectError = NotFoundError | DbError union UpdateLangProjectIdError = NotFoundError | DbError | UnauthorizedAccessError -union UpdateLangProjectIdWhereMissingError = NotFoundError | DbError | UnauthorizedAccessError - union UpdateProjectLanguageListError = NotFoundError | DbError | UnauthorizedAccessError -union UpdateProjectLanguageListWhereMissingError = NotFoundError | DbError | UnauthorizedAccessError - union UpdateProjectLexEntryCountError = NotFoundError | DbError | UnauthorizedAccessError input AddProjectMemberInput { @@ -1027,18 +1011,10 @@ input UpdateLangProjectIdInput { code: String! } -input UpdateLangProjectIdWhereMissingInput { - limit: Int! = 10 -} - input UpdateProjectLanguageListInput { code: String! } -input UpdateProjectLanguageListWhereMissingInput { - limit: Int! = 10 -} - input UpdateProjectLexEntryCountInput { code: String! }