Skip to content

Commit

Permalink
Merge pull request #1827 from qdraw/feature/202411_duplicates
Browse files Browse the repository at this point in the history
Duplicates in cache, reformat code ;; QueryFolder and test are changed
  • Loading branch information
qdraw authored Nov 13, 2024
2 parents 1d71655 + d0f9a93 commit 28e2f44
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 234 deletions.
1 change: 1 addition & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Semantic Versioning 2.0.0 is from version 0.1.6+
- [x] (Added) _Back-end_ Psd support for sync, reading & writing (no thumbnail) (PR #1817)
- [x] (Added) _Front-end_ Cache display issue with fileName contains (PR #1817)
- [x] (Changed) _Back-end_ Upgrade to .NET 8 - SDK 8.0.404 (Runtime: 8.0.11) (PR #1821)
- [x] (Fixed) _Back-end_ Prev/Next issue with duplicates in cache (PR #1827)
- [x] (Changed) _Front-end_ Update npm depedencies, leaflet changes (PR #1825)

## version 0.6.2 - 2024-10-11 {#v0.6.2}
Expand Down
57 changes: 28 additions & 29 deletions starsky/starsky.foundation.database/Helpers/Duplicate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,41 @@
using starsky.foundation.database.Interfaces;
using starsky.foundation.database.Models;

namespace starsky.foundation.database.Helpers
namespace starsky.foundation.database.Helpers;

public sealed class Duplicate
{
public sealed class Duplicate
private readonly IQuery _query;

public Duplicate(IQuery query)
{
private readonly IQuery _query;
_query = query;
}

public Duplicate(IQuery query)
{
_query = query;
}
/// <summary>
/// Check and remove duplicate from database!
/// </summary>
/// <param name="databaseSubFolderList"></param>
/// <returns></returns>
public async Task<List<FileIndexItem>> RemoveDuplicateAsync(
List<FileIndexItem> databaseSubFolderList)
{
// Get a list of duplicate items
var duplicateItemsByFilePath = databaseSubFolderList.GroupBy(item => item.FilePath)
.SelectMany(grp => grp.Skip(1).Take(1)).ToList();

/// <summary>
/// Check and remove duplicate from database
/// </summary>
/// <param name="databaseSubFolderList"></param>
/// <returns></returns>
public async Task<List<FileIndexItem>> RemoveDuplicateAsync(
List<FileIndexItem> databaseSubFolderList)
// ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
foreach ( var duplicateItemByName in duplicateItemsByFilePath )
{
// Get a list of duplicate items
var duplicateItemsByFilePath = databaseSubFolderList.GroupBy(item => item.FilePath)
.SelectMany(grp => grp.Skip(1).Take(1)).ToList();

// ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
foreach ( var duplicateItemByName in duplicateItemsByFilePath )
var duplicateItems = databaseSubFolderList.Where(p =>
p.FilePath == duplicateItemByName.FilePath).ToList();
for ( var i = 1; i < duplicateItems.Count; i++ )
{
var duplicateItems = databaseSubFolderList.Where(p =>
p.FilePath == duplicateItemByName.FilePath).ToList();
for ( var i = 1; i < duplicateItems.Count; i++ )
{
databaseSubFolderList.Remove(duplicateItems[i]);
await _query.RemoveItemAsync(duplicateItems[i]);
}
databaseSubFolderList.Remove(duplicateItems[i]);
await _query.RemoveItemAsync(duplicateItems[i]);
}

return databaseSubFolderList;
}

return databaseSubFolderList;
}
}
6 changes: 0 additions & 6 deletions starsky/starsky.foundation.database/Interfaces/IQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ Task<List<FileIndexItem>> GetObjectsByFileHashAsync(

void ResetItemByHash(string fileHash);

/// <summary>
/// Only global search for all folder
/// </summary>
/// <returns></returns>
List<FileIndexItem> GetAllFolders();

Task<List<FileIndexItem>> GetFoldersAsync(string subPath);

Task<List<FileIndexItem>> GetAllObjectsAsync(string subPath);
Expand Down
21 changes: 2 additions & 19 deletions starsky/starsky.foundation.database/Query/QueryFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ namespace starsky.foundation.database.Query;

public partial class Query // For folder displays only
{
/// <summary>
/// Query all FileIndexItems with the type folder
/// </summary>
/// <returns>List of all folders in database, including content</returns>
public List<FileIndexItem> GetAllFolders()
{
try
{
return _context.FileIndex.Where(p => p.IsDirectory == true).ToList();
}
catch ( ObjectDisposedException )
{
var context = new InjectServiceScope(_scopeFactory).Context();
return context.FileIndex.Where(p => p.IsDirectory == true).ToList();
}
}


// Class for displaying folder content
// This is the query part
Expand Down Expand Up @@ -103,8 +86,8 @@ public Tuple<bool, List<FileIndexItem>> CacheGetParentFolder(string subPath)
return fallbackResult;
}

var result = objectFileFolders as List<FileIndexItem> ??
new List<FileIndexItem>();
var result = ( objectFileFolders as List<FileIndexItem> ??
new List<FileIndexItem>() ).DistinctBy(p => p.FilePath).ToList();
return new Tuple<bool, List<FileIndexItem>>(true, result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,12 @@ private static ImageStabilisationType GetImageStabilisation(
sonyDirectory?.GetDescription(SonyType1MakernoteDirectory.TagImageStabilisation);
// 0 0x0000 Off
// 1 0x0001 On
switch ( imageStabilisation )
return imageStabilisation switch
{
case "Off":
return ImageStabilisationType.Off;
case "On":
return ImageStabilisationType.On;
}

return ImageStabilisationType.Unknown;
"Off" => ImageStabilisationType.Off,
"On" => ImageStabilisationType.On,
_ => ImageStabilisationType.Unknown
};
}

internal static string GetLocationCountryCode(List<Directory> allExifItems)
Expand Down
Loading

0 comments on commit 28e2f44

Please sign in to comment.