-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
84: Removed reset from playground app
- Loading branch information
Showing
6 changed files
with
33 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
API/ASSISTENTE.Application/Handlers/Maintenance/Commands/ResetCommand.cs
This file was deleted.
Oops, something went wrong.
41 changes: 30 additions & 11 deletions
41
API/ASSISTENTE.Infrastructure/Services/MaintenanceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,57 @@ | ||
using ASSISTENTE.Application.Abstractions.Interfaces; | ||
using ASSISTENTE.Infrastructure.Qdrant; | ||
using ASSISTENTE.Language.Enums; | ||
using ASSISTENTE.Persistence.Configuration; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace ASSISTENTE.Infrastructure.Services; | ||
|
||
public sealed class MaintenanceService( | ||
IQdrantService qdrantService | ||
IQdrantService qdrantService, | ||
IAssistenteDbContext context | ||
) : IMaintenanceService | ||
{ | ||
public async Task<Result> InitAsync() | ||
{ | ||
var resourceTypes = Enum.GetValues(typeof(ResourceType)); | ||
var results = new List<Result>(); | ||
|
||
foreach (var resourceType in Enum.GetValues(typeof(ResourceType))) | ||
var clearanceResult = await ClearDatabase(); | ||
|
||
if (clearanceResult.IsFailure) return clearanceResult; | ||
|
||
foreach (var type in resourceTypes) | ||
{ | ||
var result = await qdrantService.DropCollectionAsync($"embeddings-{type}"); | ||
|
||
results.Add(result); | ||
} | ||
|
||
foreach (var type in resourceTypes) | ||
{ | ||
var result = await qdrantService.CreateCollectionAsync($"embeddings-{resourceType}"); | ||
var result = await qdrantService.CreateCollectionAsync($"embeddings-{type}"); | ||
|
||
results.Add(result); | ||
} | ||
|
||
return Result.Combine(results); | ||
} | ||
|
||
public async Task<Result> ResetAsync() | ||
private async Task<Result> ClearDatabase() | ||
{ | ||
var results = new List<Result>(); | ||
|
||
foreach (var resourceType in Enum.GetValues(typeof(ResourceType))) | ||
try | ||
{ | ||
var result = await qdrantService.DropCollectionAsync($"embeddings-{resourceType}"); | ||
var resources = await context.Resources.ToListAsync(); | ||
|
||
results.Add(result); | ||
} | ||
context.Resources.RemoveRange(resources); | ||
|
||
return Result.Combine(results); | ||
await context.SaveChangesAsync(); | ||
|
||
return Result.Success(); | ||
} | ||
catch | ||
{ | ||
return Result.Failure("Failed to clear database"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters