-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reformat code && implement memory cache for ThumbnailQuery
- Loading branch information
Showing
10 changed files
with
423 additions
and
403 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 40 additions & 35 deletions
75
starsky/starsky.foundation.database/Thumbnails/ThumbnailQueryFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Caching.Memory; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using starsky.foundation.database.Helpers; | ||
using starsky.foundation.database.Interfaces; | ||
using starsky.foundation.database.Models; | ||
using starsky.foundation.platform.Interfaces; | ||
|
||
namespace starsky.foundation.database.Thumbnails | ||
namespace starsky.foundation.database.Thumbnails; | ||
|
||
public sealed class ThumbnailQueryFactory | ||
{ | ||
public sealed class ThumbnailQueryFactory | ||
private readonly IWebLogger _logger; | ||
private readonly IMemoryCache? _memoryCache; | ||
private readonly IServiceScopeFactory? _serviceScopeFactory; | ||
private readonly SetupDatabaseTypes? _setupDatabaseTypes; | ||
private readonly IThumbnailQuery? _thumbnailQuery; | ||
|
||
public ThumbnailQueryFactory(SetupDatabaseTypes? setupDatabaseTypes, | ||
IServiceScopeFactory? serviceScopeFactory, IThumbnailQuery? thumbnailQuery, | ||
IWebLogger logger, IMemoryCache memoryCache) | ||
{ | ||
private readonly SetupDatabaseTypes? _setupDatabaseTypes; | ||
private readonly IServiceScopeFactory? _serviceScopeFactory; | ||
private readonly IThumbnailQuery? _thumbnailQuery; | ||
private readonly IWebLogger _logger; | ||
_setupDatabaseTypes = setupDatabaseTypes; | ||
_serviceScopeFactory = serviceScopeFactory; | ||
_thumbnailQuery = thumbnailQuery; | ||
_logger = logger; | ||
_memoryCache = memoryCache; | ||
} | ||
|
||
public ThumbnailQueryFactory(SetupDatabaseTypes? setupDatabaseTypes, IServiceScopeFactory? serviceScopeFactory, IThumbnailQuery? thumbnailQuery, IWebLogger logger) | ||
public IThumbnailQuery? ThumbnailQuery() | ||
{ | ||
if ( _thumbnailQuery == null ) | ||
{ | ||
_setupDatabaseTypes = setupDatabaseTypes; | ||
_serviceScopeFactory = serviceScopeFactory; | ||
_thumbnailQuery = thumbnailQuery; | ||
_logger = logger; | ||
return null; | ||
} | ||
|
||
public IThumbnailQuery? ThumbnailQuery() | ||
var context = _setupDatabaseTypes?.BuilderDbFactory(); | ||
if ( _thumbnailQuery.GetType() == typeof(ThumbnailQuery) && context != null && | ||
_memoryCache != null ) | ||
{ | ||
if ( _thumbnailQuery == null ) | ||
{ | ||
return null; | ||
} | ||
|
||
var context = _setupDatabaseTypes?.BuilderDbFactory(); | ||
if ( _thumbnailQuery.GetType() == typeof(ThumbnailQuery) && context != null ) | ||
{ | ||
return new ThumbnailQuery(context, _serviceScopeFactory, _logger); | ||
} | ||
|
||
// FakeIQuery should skip creation | ||
var isAnyContentIncluded = _thumbnailQuery.GetReflectionFieldValue<List<ThumbnailItem>?>("_content")?.Count != 0; | ||
|
||
if ( !isAnyContentIncluded ) | ||
{ | ||
return Activator.CreateInstance(_thumbnailQuery.GetType(), | ||
context, _serviceScopeFactory, _logger) as IThumbnailQuery; | ||
} | ||
|
||
_logger.LogInformation("FakeIThumbnailQuery _content detected"); | ||
return _thumbnailQuery; | ||
return new ThumbnailQuery(context, _serviceScopeFactory, _logger, _memoryCache); | ||
} | ||
|
||
// FakeIQuery should skip creation | ||
var isAnyContentIncluded = | ||
_thumbnailQuery.GetReflectionFieldValue<List<ThumbnailItem>?>("_content")?.Count != 0; | ||
|
||
if ( !isAnyContentIncluded ) | ||
{ | ||
return Activator.CreateInstance(_thumbnailQuery.GetType(), | ||
context, _serviceScopeFactory, _logger) as IThumbnailQuery; | ||
} | ||
|
||
_logger.LogInformation("FakeIThumbnailQuery _content detected"); | ||
return _thumbnailQuery; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.