/// <summary> /// Query the database and check if an single item has changed /// </summary> /// <param name="subPath">path</param> /// <param name="updateDelegate">realtime updates, can be null to ignore</param> /// <returns>updated item with status</returns> internal async Task <FileIndexItem> SingleFile(string subPath, ISynchronize.SocketUpdateDelegate updateDelegate = null) { // route with database check if (_appSettings.ApplicationType == AppSettings.StarskyAppType.WebController) { _logger.LogInformation($"[SingleFile/db] {subPath} " + Synchronize.DateTimeDebug()); } // Sidecar files are updated but ignored by the process await UpdateSidecarFile(subPath); // ignore all the 'wrong' files var statusItem = CheckForStatusNotOk(subPath); if (statusItem.Status != FileIndexItem.ExifStatus.Ok) { _logger.LogDebug($"[SingleFile/db] status {statusItem.Status} for {subPath} {Synchronize.DateTimeDebug()}"); return(statusItem); } // temp disable caching TimeSpan.FromSeconds(1) var dbItem = await _query.GetObjectByFilePathAsync(subPath); // // // when item does not exist in Database if (dbItem == null) { return(await NewItem(statusItem, subPath)); } // Cached values are not checked for performance reasons if (dbItem.Status == FileIndexItem.ExifStatus.OkAndSame) { _logger.LogDebug($"[SingleFile/db] OkAndSame {subPath} {Synchronize.DateTimeDebug()}"); return(dbItem); } var(isSame, updatedDbItem) = await SizeFileHashIsTheSame(dbItem); if (!isSame) { if (updateDelegate != null) { await updateDelegate(new List <FileIndexItem> { dbItem }); } return(await UpdateItem(dbItem, updatedDbItem.Size, subPath)); } // to avoid reSync updatedDbItem.Status = FileIndexItem.ExifStatus.OkAndSame; AddDeleteStatus(statusItem, FileIndexItem.ExifStatus.DeletedAndSame); _logger.LogInformation($"[SingleFile/db] Same: {updatedDbItem.Status} for: {updatedDbItem.FilePath}"); return(updatedDbItem); }
public async Task <List <string> > CleanAllUnusedFilesAsync(int chunkSize = 50) { if (!_thumbnailStorage.ExistFolder("/")) { throw new DirectoryNotFoundException("Thumbnail folder not found"); } var allThumbnailFiles = _thumbnailStorage .GetAllFilesInDirectory(null).ToList(); _logger.LogDebug($"Total files in thumb dir: {allThumbnailFiles.Count}"); var deletedFileHashes = new List <string>(); foreach (var fileNamesInChunk in allThumbnailFiles.ChunkyEnumerable(chunkSize)) { var itemsInChunk = GetFileNamesWithExtension(fileNamesInChunk.ToList()); try { await LoopThoughChunk(itemsInChunk, deletedFileHashes); } catch (Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException exception) { _logger.LogInformation($"[CleanAllUnusedFiles] catch-ed and " + $"skip {string.Join(",", itemsInChunk.ToList())} ~ {exception.Message}", exception); } } return(deletedFileHashes); }
public void SetGetObjectByFilePathCache(string filePath, FileIndexItem result, TimeSpan?cacheTime) { if (_cache == null || cacheTime == null || result == null) { _logger.LogDebug("SetGetObjectByFilePathCache not used"); return; } _cache.Set(GetObjectByFilePathAsyncCacheName(filePath), result, cacheTime.Value); }
// Define the event handlers. /// <summary> /// Specify what is done when a file is changed. e.FullPath /// </summary> /// <param name="source"></param> /// <param name="e"></param> internal void OnChanged(object source, FileSystemEventArgs e) { if (e.FullPath.EndsWith(".tmp") || !ExtensionRolesHelper.IsExtensionSyncSupported(e.FullPath)) { return; } _webLogger.LogDebug($"[DiskWatcher] " + $"{e.FullPath} OnChanged ChangeType is: {e.ChangeType} " + DateTimeDebug()); _queueProcessor.QueueInput(e.FullPath, null, e.ChangeType); // Specify what is done when a file is changed, created, or deleted. }