fixes some concurrency issues on filecount and failed files
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
This commit is contained in:
parent
809f892b07
commit
adcf8b1504
@ -1,4 +1,5 @@
|
||||
using System.Threading.Channels;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Channels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -9,9 +10,10 @@ namespace PiwigoDirectorySync.Services;
|
||||
|
||||
internal class FileIndexer : IFileIndexer
|
||||
{
|
||||
private readonly IList<string> _failedFiles = new List<string>();
|
||||
private readonly ConcurrentBag<string> _failedFiles = new();
|
||||
private readonly ILogger<FileIndexer> _logger;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private int _totalFilesScanned;
|
||||
|
||||
public FileIndexer(ILogger<FileIndexer> logger, IServiceProvider serviceProvider)
|
||||
{
|
||||
@ -19,8 +21,9 @@ internal class FileIndexer : IFileIndexer
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public int TotalFilesScanned { get; private set; }
|
||||
public IReadOnlyCollection<string> FailedFiles => _failedFiles.AsReadOnly();
|
||||
public int TotalFilesScanned => _totalFilesScanned;
|
||||
|
||||
public IReadOnlyCollection<string> FailedFiles => _failedFiles;
|
||||
|
||||
public async Task StartProcessingAsync(Channel<string> fileQueue, int piwigoServerId, CancellationToken ct)
|
||||
{
|
||||
@ -74,7 +77,7 @@ internal class FileIndexer : IFileIndexer
|
||||
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
||||
TotalFilesScanned++;
|
||||
Interlocked.Add(ref _totalFilesScanned, 1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user