Skip to content

Conversation

@winklertomas
Copy link
Contributor

Motivation

Add support for new used-in delivery API feature.

Checklist

  • Code follows coding conventions held in this repo
  • Automated tests have been added
  • Tests are passing
  • Docs have been updated (if applicable)
  • Temporary settings (e.g. variables used during development and testing) have been reverted to defaults

Release date

Please do not release before the used-in is released in the production. The early access should be released in the middle of March, we will let you know.

@winklertomas winklertomas requested review from a team and pokornyd as code owners February 28, 2025 14:03
Copy link
Member

@pokornyd pokornyd left a comment

Choose a reason for hiding this comment

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

add null handling and consider changing EnumerateFeed to async

/// <param name="codename">The codename of a content item.</param>
/// <param name="parameters">A collection of query parameters for filtering.</param>
/// <returns>The <see cref="DeliveryUsedInItems"/> instance that can be used to enumerate through content item parents for the specified item codename. If no query parameters are specified, default language parents are enumerated.</returns>
public IDeliveryItemsFeed<IUsedInItem> GetItemUsedIn(string codename, IEnumerable<IQueryParameter> parameters = null)
Copy link
Member

Choose a reason for hiding this comment

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

existing methods accepting a codename parameter have null handling in place. consider adding it to all usedIn methods as well:

if (codename == null)
{
    throw new ArgumentNullException(nameof(codename), "The codename of a content item is not specified.");
}

/// <returns>The <see cref="DeliveryUsedInItems"/> instance that can be used to enumerate through asset parents for the specified asset codename. If no query parameters are specified, default language parents are enumerated.</returns>
public IDeliveryItemsFeed<IUsedInItem> GetAssetUsedIn(string codename, IEnumerable<IQueryParameter> parameters = null)
{
ValidateUsedInParameters(parameters);
Copy link
Member

Choose a reason for hiding this comment

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

also null handling:

if (codename == null)
{
    throw new ArgumentNullException(nameof(codename), "The codename of an asset is not specified.");
}

#endregion
#region "Private methods"
private static IEnumerable<T> EnumerateFeed<T>(IDeliveryItemsFeed<T> feed) where T : class
{
Copy link
Member

Choose a reason for hiding this comment

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

this method is synchronous but invokes an async method and waits for its result, effectively blocking threads. not sure if this is a valid scenario under the circumstances, but I'm not familiar with Rx so I asked AI about it.

the fix is simple, make the method async and have it return IAsyncEnumerable:

private static async IAsyncEnumerable<T> EnumerateFeed<T>(IDeliveryItemsFeed<T> feed) where T : class
{
    while (feed.HasMoreResults)
    {
        var batch = await feed.FetchNextBatchAsync();
        foreach (var contentItem in batch.Items)
        {
            yield return contentItem;
        }
    }
}

however, related methods would need to be updated as well.

again, I'm not sure if thread locking or even deadlocks can be a thing in our scenario. also, Rx is used much less, compared to async, so I leave this at your decision.

@pokornyd pokornyd merged commit f0d1601 into kontent-ai:master Apr 9, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants