mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Implements file hashing media library scan job
This commit is contained in:
1 parent
66998055f0
commit
03a000e1e4
63 files changed
+2009
-287
No files matched your search
@@ -31,9 +31,9 @@ internal sealed class RolePermissionRepository : IRolePermissionRepository
|
||||
/// <param name="rolePermission">The authorization role permission to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(RolePermissionEntity rolePermission, CancellationToken cancellationToken)
|
||||
public Task<ErrorOr<Created>> InsertAsync(RolePermissionEntity rolePermission, CancellationToken cancellationToken)
|
||||
{
|
||||
_luminaDbContext.RolePermissions.Add(rolePermission);
|
||||
return await Task.FromResult(Result.Created);
|
||||
return Task.FromResult(ErrorOrFactory.From(Result.Created));
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,9 @@ internal sealed class UserRoleRepository : IUserRoleRepository
|
||||
/// <param name="userRole">The authorization user role to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(UserRoleEntity userRole, CancellationToken cancellationToken)
|
||||
public Task<ErrorOr<Created>> InsertAsync(UserRoleEntity userRole, CancellationToken cancellationToken)
|
||||
{
|
||||
_luminaDbContext.UserRoles.Add(userRole);
|
||||
return await Task.FromResult(Result.Created);
|
||||
return Task.FromResult(ErrorOrFactory.From(Result.Created));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.Repositories.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Repository for media library scan results.
|
||||
/// </summary>
|
||||
internal sealed class LibraryScanResultRepository : ILibraryScanResultRepository
|
||||
{
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryScanResultRepository"/> class.
|
||||
/// </summary>
|
||||
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
|
||||
public LibraryScanResultRepository(LuminaDbContext luminaDbContext)
|
||||
{
|
||||
_luminaDbContext = luminaDbContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new library scan result.
|
||||
/// </summary>
|
||||
/// <param name="libraryScan">The library scan result to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Task<ErrorOr<Created>> InsertAsync(LibraryScanResultEntity libraryScan, CancellationToken cancellationToken)
|
||||
{
|
||||
_luminaDbContext.LibraryScanResults.Add(libraryScan);
|
||||
return Task.FromResult(ErrorOrFactory.From(Result.Created));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all media library scan results that belong to the last scan of a library identified by <paramref name="libraryId"/>, from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The unique identifier of the library for which to get the results of the last scans.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a path mapped dictionary of <see cref="LibraryScanResultEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<Dictionary<string, LibraryScanResultEntity>>> GetPathMappedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.LibraryScanResults
|
||||
.Where(libraryScanResult =>
|
||||
libraryScanResult.LibraryScan.LibraryId == libraryId && // navigation property
|
||||
libraryScanResult.LibraryScanId == _luminaDbContext.LibraryScans // subquery for latest scan Id
|
||||
.Where(libraryScan => libraryScan.LibraryId == libraryId)
|
||||
.OrderByDescending(libraryScan => libraryScan.CreatedOnUtc)
|
||||
.Select(libraryScan => libraryScan.Id)
|
||||
.FirstOrDefault())
|
||||
.ToDictionaryAsync( // since these are used in large quantity comparisons, dictionary allows for O(1) lookups, instead of lists, with O(n * m)
|
||||
libraryScanResult => libraryScanResult.Path,
|
||||
libraryScanResult => libraryScanResult,
|
||||
StringComparer.Ordinal, // UNIX systems allow for case sensitive file paths
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user