Skip to content

Commit

Permalink
Make "update where missing" calls HTTP POSTs again
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rmunn committed Jul 25, 2024
1 parent 25665cc commit bebba76
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 82 deletions.
42 changes: 42 additions & 0 deletions backend/LexBoxApi/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,48 @@ private async Task StreamHttpResponse(HttpContent hgResult)
await hgResult.CopyToAsync(writer.AsStream());
}

[HttpPost("updateMissingLanguageList")]
public async Task<ActionResult<string[]>> 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<string>(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<ActionResult<string[]>> 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<string>(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<ActionResult> QueueUpdateProjectMetadataTask(string projectCode)
{
Expand Down
58 changes: 0 additions & 58 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,35 +348,6 @@ public async Task<IQueryable<Project>> UpdateProjectLanguageList(string code,
return dbContext.Projects.Where(p => p.Id == projectId);
}

[Error<NotFoundException>]
[Error<DbError>]
[Error<UnauthorizedAccessException>]
[UseMutationConvention]
[UseProjection]
[AdminRequired]
public async Task<IQueryable<Project>> 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<Guid>(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<NotFoundException>]
[Error<DbError>]
[Error<UnauthorizedAccessException>]
Expand All @@ -397,35 +368,6 @@ public async Task<IQueryable<Project>> UpdateLangProjectId(string code,
return dbContext.Projects.Where(p => p.Id == projectId);
}

[Error<NotFoundException>]
[Error<DbError>]
[Error<UnauthorizedAccessException>]
[UseMutationConvention]
[UseProjection]
[AdminRequired]
public async Task<IQueryable<Project>> 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<Guid>(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<NotFoundException>]
[Error<LastMemberCantLeaveException>]
[UseMutationConvention]
Expand Down
24 changes: 0 additions & 24 deletions frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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!]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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!
}
Expand Down

0 comments on commit bebba76

Please sign in to comment.