Skip to content

Commit

Permalink
Refactor repositories and add async media library fetch
Browse files Browse the repository at this point in the history
Modified ContentTypeRepository to remove conditional execution
and directly call ExecuteContentQuery. Updated IMediaFileRepository
to include GetMediaLibraryByIdAsync method. Renamed constructor
parameter in MediaFileRepository and implemented the new async
method with null check for progressiveCache.
  • Loading branch information
brandonhenricks committed Jan 9, 2025
1 parent fc25d02 commit f370021
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ public async Task<IEnumerable<TEntity>> GetAllAsync(string? languageName, int ma
config.When(maxLinkedItems > 0, linkOptions => linkOptions.WithLinkedItems(maxLinkedItems)))
.When(!string.IsNullOrEmpty(languageName), lang => lang.InLanguage(languageName));

var queryOptions = GetQueryExecutionOptions();

if (WebsiteChannelContext.IsPreview)
{
return await Executor.GetMappedResult<TEntity>(builder, queryOptions,
cancellationToken: cancellationToken);
}

var result = await ExecuteContentQuery<TEntity>(builder,
() => CacheDependencyHelper.CreateContentItemTypeCacheDependency([contentType]),
cancellationToken, CachePrefix, nameof(GetAllAsync), contentType, maxLinkedItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ namespace XperienceCommunity.DataRepository.Interfaces;
/// </summary>
public interface IMediaFileRepository
{

/// <summary>
/// Retrieves a media library by its identifier.
/// </summary>
/// <param name="mediaLibraryId"></param>
/// <param name="cancellationToken"></param>
/// <returns>A task that represent the asynchronous operation. The task result contains a <see cref="MediaLibraryInfo"/>.</returns>
Task<MediaLibraryInfo?> GetMediaLibraryByIdAsync(int mediaLibraryId,
CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves a list of media files based on the provided GUIDs.
/// </summary>
Expand Down
15 changes: 13 additions & 2 deletions src/XperienceCommunity.DataRepository/MediaFileRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ public sealed class MediaFileRepository : IMediaFileRepository
private readonly IProgressiveCache cache;
private readonly int cacheMinutes;

public MediaFileRepository(IProgressiveCache cache, RepositoryOptions options)
public MediaFileRepository(IProgressiveCache progressiveCache, RepositoryOptions options)
{
this.cache = cache;
cache = progressiveCache ?? throw new ArgumentNullException(nameof(progressiveCache));
cacheMinutes = options?.CacheMinutes ?? 10;
}

/// <inheritdoc />
public async Task<MediaLibraryInfo?> GetMediaLibraryByIdAsync(int mediaLibraryId,
CancellationToken cancellationToken = default)
{
var objectQuery = await new ObjectQuery<MediaLibraryInfo>()
.WhereEquals(nameof(MediaLibraryInfo.LibraryID), mediaLibraryId)
.GetEnumerableTypedResultAsync(cancellationToken: cancellationToken);

return objectQuery?.FirstOrDefault();
}

/// <inheritdoc />
public async Task<ImmutableList<MediaFileInfo>> GetAssetsFromRelatedItemsAsync(IEnumerable<AssetRelatedItem> items,
CancellationToken cancellationToken = default)
Expand Down

0 comments on commit f370021

Please sign in to comment.