Skip to content

Commit

Permalink
Merge pull request #1803 from qdraw/feature/202411_open_folder
Browse files Browse the repository at this point in the history
Feature/202411 open folder
  • Loading branch information
qdraw authored Nov 8, 2024
2 parents 24ce953 + 817604f commit 6e01979
Show file tree
Hide file tree
Showing 13 changed files with 601 additions and 506 deletions.
2 changes: 2 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Semantic Versioning 2.0.0 is from version 0.1.6+
- [x] (Fixed) _Back-end_ Timeout in Thumbnail cleaner fixed (PR #1798)
- [x] (Fixed) _Back-end_ Add logging for thumbnail background scanning (PR #1798)
- [x] (Fixed) _Front-end_ Invalid date parsing (PR #1802, Issue #1508)
- [x] (Fixed) _Back-end_ Fix for query home item (PR #1803)
- [x] (Added) _Front-end_ Add UI element to open current folder in archive view (PR #1803)

## version 0.6.2 - 2024-10-11 {#v0.6.2}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public DatabaseThumbnailGenerationService(IQuery query, IWebLogger logger,

public async Task StartBackgroundQueue()
{
// why Task.Yield -> https://medium.com/@thepen0411/how-to-resolve-the-net-background-service-blocking-issue-c96086de8acd
await Task.Yield();

if ( _thumbnailQuery.IsRunningJob() )
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,156 +10,161 @@
using starsky.foundation.database.Models;
using starsky.foundation.platform.Helpers;

namespace starsky.foundation.database.Query
namespace starsky.foundation.database.Query;

/// <summary>
/// QueryGetObjectsByFilePathAsync.cs
/// </summary>
public partial class Query : IQuery
{
public async Task<List<FileIndexItem>> GetObjectsByFilePathAsync(string inputFilePath,
bool collections)
{
return await GetObjectsByFilePathAsync(new List<string> { inputFilePath }, collections);
}

/// <summary>
/// QueryGetObjectsByFilePathAsync.cs
/// Query by
/// </summary>
public partial class Query : IQuery
/// <param name="inputFilePaths">list of paths</param>
/// <param name="collections">uses collections </param>
/// <returns>list with items</returns>
public async Task<List<FileIndexItem>> GetObjectsByFilePathAsync(
List<string> inputFilePaths, bool collections)
{
public async Task<List<FileIndexItem>> GetObjectsByFilePathAsync(string inputFilePath,
bool collections)
var resultFileIndexItemsList = new List<FileIndexItem>();
var toQueryPaths = new List<string>();
foreach ( var path in inputFilePaths )
{
return await GetObjectsByFilePathAsync(new List<string> { inputFilePath }, collections);
}
var parentPath = FilenamesHelper.GetParentPath(path);

/// <summary>
/// Query
/// </summary>
/// <param name="inputFilePaths">list of paths</param>
/// <param name="collections">uses collections </param>
/// <returns>list with items</returns>
public async Task<List<FileIndexItem>> GetObjectsByFilePathAsync(
List<string> inputFilePaths, bool collections)
{
var resultFileIndexItemsList = new List<FileIndexItem>();
var toQueryPaths = new List<string>();
foreach ( var path in inputFilePaths )
var (success, cachedResult) = CacheGetParentFolder(parentPath);

List<FileIndexItem>? item = null;
switch ( collections )
{
var parentPath = FilenamesHelper.GetParentPath(path);

var (success, cachedResult) = CacheGetParentFolder(parentPath);

List<FileIndexItem>? item = null;
switch ( collections )
{
case false:
if ( !success )
{
break;
}

item = cachedResult.Where(p =>
p.ParentDirectory == parentPath &&
p.FileName == FilenamesHelper.GetFileName(path)).ToList();
case false:
if ( !success )
{
break;
case true:
if ( !success )
{
break;
}

item = cachedResult.Where(p =>
p.ParentDirectory == parentPath &&
p.FileCollectionName ==
FilenamesHelper.GetFileNameWithoutExtension(path)).ToList();
}

item = cachedResult.Where(p =>
p.ParentDirectory == parentPath &&
p.FileName == FilenamesHelper.GetFileName(path)).ToList();
break;
case true:
if ( !success )
{
break;
}
}

if ( !success || item == null || item.Count == 0 )
{
toQueryPaths.Add(path);
continue;
}
item = cachedResult.Where(p =>
p.ParentDirectory == parentPath &&
p.FileCollectionName ==
FilenamesHelper.GetFileNameWithoutExtension(path)).ToList();
break;
}

resultFileIndexItemsList.AddRange(item);
if ( !success || item == null || item.Count == 0 )
{
toQueryPaths.Add(path);
continue;
}

// Query only if not in cache
var fileIndexItemsList =
await GetObjectsByFilePathQuery(toQueryPaths.ToArray(), collections);
resultFileIndexItemsList.AddRange(fileIndexItemsList);
return resultFileIndexItemsList;
resultFileIndexItemsList.AddRange(item);
}

/// <summary>
/// Switch between collections and non-collections
/// </summary>
/// <param name="inputFilePaths">list of paths</param>
/// <param name="collections">[when true] hide raws or everything with the same name (without extension)</param>
/// <returns></returns>
internal async Task<List<FileIndexItem>> GetObjectsByFilePathQuery(string[] inputFilePaths,
bool collections)
{
if ( inputFilePaths.Length == 0 )
{
return new List<FileIndexItem>();
}
// Query only if not in cache
var fileIndexItemsList =
await GetObjectsByFilePathQuery(toQueryPaths.ToArray(), collections);
resultFileIndexItemsList.AddRange(fileIndexItemsList);
return resultFileIndexItemsList;
}

if ( collections )
{
return await GetObjectsByFilePathCollectionQueryAsync(inputFilePaths.ToList());
}

return await GetObjectsByFilePathQueryAsync(inputFilePaths.ToList());
/// <summary>
/// Skip cache
/// </summary>
/// <param name="filePathList"></param>
/// <returns></returns>
[SuppressMessage("Sonar", "S1696:NullReferenceException should not be caught")]
public async Task<List<FileIndexItem>> GetObjectsByFilePathQueryAsync(
List<string> filePathList)
{
async Task<List<FileIndexItem>> LocalQuery(ApplicationDbContext context)
{
var result = await context.FileIndex.TagWith("GetObjectsByFilePathQueryAsync")
.Where(p =>
p.FilePath != null && filePathList.Contains(p.FilePath)).ToListAsync();
return FormatOk(result);
}


/// <summary>
/// Skip cache
/// </summary>
/// <param name="filePathList"></param>
/// <returns></returns>
[SuppressMessage("Sonar", "S1696:NullReferenceException should not be caught")]
public async Task<List<FileIndexItem>> GetObjectsByFilePathQueryAsync(
List<string> filePathList)
try
{
async Task<List<FileIndexItem>> LocalQuery(ApplicationDbContext context)
return await LocalQuery(_context);
}
// Rewrite in future to avoid using catch NullReferenceException
catch ( NullReferenceException ex1 )
{
_logger.LogInformation(
$"catch-ed null ref exception: {string.Join(",", filePathList.ToArray())} {ex1.StackTrace}",
ex1);
await Task.Delay(10);
// System.NullReferenceException: Object reference not set to an instance of an object.
// at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet()
try
{
var result = await context.FileIndex.TagWith("GetObjectsByFilePathQueryAsync")
.Where(p =>
p.FilePath != null && filePathList.Contains(p.FilePath)).ToListAsync();
return FormatOk(result);
return await LocalQuery(new InjectServiceScope(_scopeFactory)
.Context());
}

try
catch ( MySqlProtocolException )
{
return await LocalQuery(_context);
// Packet received out-of-order. Expected 1; got 2.
return await LocalQuery(
new InjectServiceScope(_scopeFactory).Context());
}
// Rewrite in future to avoid using catch NullReferenceException
catch ( NullReferenceException ex1 )
catch ( NullReferenceException ex2 )
{
_logger.LogInformation(
$"catch-ed null ref exception: {string.Join(",", filePathList.ToArray())} {ex1.StackTrace}",
ex1);
await Task.Delay(10);
// System.NullReferenceException: Object reference not set to an instance of an object.
// at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet()
try
{
return await LocalQuery(new InjectServiceScope(_scopeFactory)
.Context());
}
catch ( MySqlProtocolException )
{
// Packet received out-of-order. Expected 1; got 2.
return await LocalQuery(
new InjectServiceScope(_scopeFactory).Context());
}
// Rewrite in future to avoid using catch NullReferenceException
catch ( NullReferenceException ex2 )
{
_logger.LogInformation(
$"catch-ed null ref exception 2: {string.Join(",", filePathList.ToArray())} {ex2.StackTrace}",
ex2);
throw;
}
}
catch ( InvalidOperationException )
{
// System.InvalidOperationException or ObjectDisposedException: Cannot Open when State is Connecting.
return await LocalQuery(new InjectServiceScope(_scopeFactory).Context());
$"catch-ed null ref exception 2: {string.Join(",", filePathList.ToArray())} {ex2.StackTrace}",
ex2);
throw;
}
}
catch ( InvalidOperationException )
{
// System.InvalidOperationException or ObjectDisposedException: Cannot Open when State is Connecting.
return await LocalQuery(new InjectServiceScope(_scopeFactory).Context());
}
}

/// <summary>
/// Switch between collections and non-collections
/// </summary>
/// <param name="inputFilePaths">list of paths</param>
/// <param name="collections">
/// [when true] hide raws or everything with the same name (without
/// extension)
/// </param>
/// <returns></returns>
internal async Task<List<FileIndexItem>> GetObjectsByFilePathQuery(string[] inputFilePaths,
bool collections)
{
if ( inputFilePaths.Length == 0 )
{
return [];
}

List<FileIndexItem> result;
if ( collections )
{
result = await GetObjectsByFilePathCollectionQueryAsync(inputFilePaths.ToList());
return result;
}

result = await GetObjectsByFilePathQueryAsync(inputFilePaths.ToList());
return result;
}
}
Loading

1 comment on commit 6e01979

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.