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

add a Try Fw Lite button to project pages #1375

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using LexCore.ServiceInterfaces;
using LexData;
using Microsoft.EntityFrameworkCore;
using SIL.Harmony.Core;

namespace LexBoxApi.GraphQL.CustomTypes;

public class IsHarmonyProjectDataLoader(
LexBoxDbContext dbContext,
IBatchScheduler batchScheduler,
DataLoaderOptions options)
: BatchDataLoader<Guid, bool>(batchScheduler, options), IIsHarmonyProjectDataLoader
{
protected override async Task<IReadOnlyDictionary<Guid, bool>> LoadBatchAsync(IReadOnlyList<Guid> keys, CancellationToken cancellationToken)
{
var isHarmonyProject = await dbContext.Set<ServerCommit>()
.Where(c => keys.Contains(c.ProjectId))
.Select(c => c.ProjectId)
.Distinct()
.ToArrayAsync(cancellationToken);
return keys.ToDictionary(k => k, k => isHarmonyProject.Contains(k));
}
}
17 changes: 17 additions & 0 deletions backend/LexBoxApi/GraphQL/GraphQlSetupKernel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using DataAnnotatedModelValidations;
using HotChocolate.Diagnostics;
using LexBoxApi.GraphQL.CustomFilters;
using LexBoxApi.GraphQL.CustomTypes;
using LexBoxApi.Services;
using LexCore.ServiceInterfaces;
using LexData;
using LfClassicData;
using Microsoft.Extensions.Options;
using Polly;

namespace LexBoxApi.GraphQL;

Expand All @@ -15,6 +20,18 @@ public static void AddLexGraphQL(this IServiceCollection services, IHostEnvironm
if (forceGenerateSchema || env.IsDevelopment())
services.AddHostedService<DevGqlSchemaWriterService>();

services.AddScoped<IIsHarmonyProjectDataLoader, IsHarmonyProjectDataLoader>();
services.AddScoped<IIsLanguageForgeProjectDataLoader, IsLanguageForgeProjectDataLoader>();
services.AddResiliencePipeline<string, IReadOnlyDictionary<string, bool>>(
IsLanguageForgeProjectDataLoader.ResiliencePolicyName,
(builder, context) =>
{
builder.ConfigureTelemetry(context.ServiceProvider.GetRequiredService<ILoggerFactory>());
IsLanguageForgeProjectDataLoader.ConfigureResiliencePipeline(builder,
context.ServiceProvider.GetRequiredService<IOptions<LfClassicConfig>>().Value
.IsLfProjectConnectionRetryTimeout);
});

services
.AddGraphQLServer()
.ModifyCostOptions(options =>
Expand Down
6 changes: 0 additions & 6 deletions backend/LexBoxApi/LexBoxKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ public static void AddLexBoxApi(this IServiceCollection services,
services.AddHostedService<HgService>();
services.AddTransient<HgWebHealthCheck>();
services.AddTransient<FwHeadlessHealthCheck>();
services.AddScoped<IIsLanguageForgeProjectDataLoader, IsLanguageForgeProjectDataLoader>();
services.AddResiliencePipeline<string, IReadOnlyDictionary<string, bool>>(IsLanguageForgeProjectDataLoader.ResiliencePolicyName, (builder, context) =>
{
builder.ConfigureTelemetry(context.ServiceProvider.GetRequiredService<ILoggerFactory>());
IsLanguageForgeProjectDataLoader.ConfigureResiliencePipeline(builder, context.ServiceProvider.GetRequiredService<IOptions<LfClassicConfig>>().Value.IsLfProjectConnectionRetryTimeout);
});
services.AddScoped<ILexProxyService, LexProxyService>();
services.AddSingleton<ISendReceiveService, SendReceiveService>();
services.AddSingleton<LexboxLinkGenerator>();
Expand Down
1 change: 0 additions & 1 deletion backend/LexBoxApi/Services/DevGqlSchemaWriterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public static async Task GenerateGqlSchema(string[] args)
.AddSingleton<IHostLifetime, ConsoleLifetime>()
.AddScoped<IEmailService, EmailService>()
.AddScoped<IHgService, HgService>()
.AddScoped<IIsLanguageForgeProjectDataLoader, IsLanguageForgeProjectDataLoader>()
.AddScoped<LoggedInContext>()
.AddScoped<LexBoxDbContext>()
.AddScoped<IPermissionService, PermissionService>()
Expand Down
9 changes: 9 additions & 0 deletions backend/LexCore/Entities/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public Task<bool> GetIsLanguageForgeProject(IIsLanguageForgeProjectDataLoader lo
}
return Task.FromResult(false);
}

public Task<bool> GetHasHarmonyCommits(IIsHarmonyProjectDataLoader loader)
{
if (Type is ProjectType.Unknown or ProjectType.FLEx)
{
return loader.LoadAsync(Id);
}
return Task.FromResult(false);
}
}

public enum ProjectMigrationStatus
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace LexCore.ServiceInterfaces;

public interface IIsHarmonyProjectDataLoader
{
Task<bool> LoadAsync(Guid projectId, CancellationToken cancellationToken = default);
}
4 changes: 2 additions & 2 deletions backend/LexData/Entities/CommitEntityConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public void Configure(EntityTypeBuilder<ServerCommit> builder)
builder.ToTable("CrdtCommits");
builder.HasKey(c => c.Id);
builder.ComplexProperty(c => c.HybridDateTime);
builder.HasOne<FlexProjectMetadata>().WithMany()
.HasPrincipalKey(f => f.ProjectId)
builder.HasOne<Project>().WithMany()
.HasPrincipalKey(project => project.Id)
.HasForeignKey(c => c.ProjectId);
builder.Property(c => c.Metadata).HasConversion(
m => JsonSerializer.Serialize(m, (JsonSerializerOptions?)null),
Expand Down
Loading
Loading