Skip to content

Commit

Permalink
Merge pull request #1 from brandonhenricks/feature/expression-visitor…
Browse files Browse the repository at this point in the history
…-refactor

Feature/expression visitor refactor
  • Loading branch information
brandonhenricks authored Jul 14, 2024
2 parents 1d04689 + 2e80c36 commit 8226645
Show file tree
Hide file tree
Showing 13 changed files with 800 additions and 660 deletions.
22 changes: 18 additions & 4 deletions src/XperienceCommunity.DataContext/ContentItemContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ContentItemContext(IWebsiteChannelContext websiteChannelContext,
() => _contentQueryExecutor.ExecuteQueryAsync(queryBuilder, queryOptions, cancellationToken),
GetCacheKey(queryBuilder));

return result.FirstOrDefault();
return result?.FirstOrDefault();
}

public IDataContext<T> IncludeTotalCount(bool includeTotalCount)
Expand Down Expand Up @@ -132,9 +132,11 @@ public async Task<IEnumerable<T>> ToListAsync(CancellationToken cancellationToke

var queryOptions = CreateQueryOptions();

return await GetOrCacheAsync(
var results= await GetOrCacheAsync(
() => _contentQueryExecutor.ExecuteQueryAsync(queryBuilder, queryOptions, cancellationToken),
GetCacheKey(queryBuilder));

return results ?? [];
}

/// <summary>
Expand Down Expand Up @@ -223,9 +225,14 @@ private ContentItemQueryBuilder BuildQuery(Expression expression, int? topN = nu
subQuery.Offset(_offset.Item1.Value, _offset.Item2.Value);
}
var visitor = new ContentItemQueryExpressionVisitor(subQuery);
var manager = new QueryParameterManager(subQuery);
var visitor = new ContentItemQueryExpressionVisitor(manager);
visitor.Visit(expression);
// Apply conditions before returning the query parameters
manager.ApplyConditions();
});

if (!string.IsNullOrEmpty(_language))
Expand Down Expand Up @@ -267,7 +274,7 @@ private string GetCacheKey(ContentItemQueryBuilder queryBuilder)
/// <param name="executeFunc">The function to execute if cache is bypassed or data is not found.</param>
/// <param name="cacheKey">The cache key.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the cached or executed data.</returns>
private async Task<T> GetOrCacheAsync<T>(Func<Task<T>> executeFunc, string cacheKey) where T : class
private async Task<T?> GetOrCacheAsync<T>(Func<Task<T>> executeFunc, string cacheKey) where T : class

Check warning on line 277 in src/XperienceCommunity.DataContext/ContentItemContext.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'T' has the same name as the type parameter from outer type 'ContentItemContext<T>'

Check warning on line 277 in src/XperienceCommunity.DataContext/ContentItemContext.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'T' has the same name as the type parameter from outer type 'ContentItemContext<T>'

Check warning on line 277 in src/XperienceCommunity.DataContext/ContentItemContext.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'T' has the same name as the type parameter from outer type 'ContentItemContext<T>'

Check warning on line 277 in src/XperienceCommunity.DataContext/ContentItemContext.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'T' has the same name as the type parameter from outer type 'ContentItemContext<T>'
{
if (_websiteChannelContext.IsPreview)
{
Expand All @@ -280,6 +287,13 @@ private async Task<T> GetOrCacheAsync<T>(Func<Task<T>> executeFunc, string cache
{
var result = await executeFunc();
cs.BoolCondition = result != null;
if (!cs.Cached)
{
return result;
}
cs.CacheDependency = CacheHelper.GetCacheDependency(GetCacheDependencies(result));
return result;
Expand Down
Loading

0 comments on commit 8226645

Please sign in to comment.