Skip to content

Commit

Permalink
Improve performance of GetProjectReference in ProjectContentResolver.cs
Browse files Browse the repository at this point in the history
Change approach of GetProjectReference method to get project items from ContentLink directly, then checking if any match the projectId, instead of getting all items in project and iterating all to check for a match of the contentLink.

This will be an improvement on performance assuming the number of projectItems matching the Contentlink in any project is less than the total number of items in a project.
dwiersmastratasys authored Jan 10, 2025
1 parent 6d33d06 commit 19291df
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Advanced.CMS.ExternalReviews/ProjectContentResolver.cs
Original file line number Diff line number Diff line change
@@ -20,12 +20,10 @@ public ProjectContentResolver(ProjectRepository projectRepository)

public ContentReference GetProjectReference(ContentReference contentLink, int projectId, string language)
{
var items = _projectRepository.ListItems(projectId);

var item = items.FirstOrDefault(
x => x.ContentLink.ToReferenceWithoutVersion() == contentLink.ToReferenceWithoutVersion()
&& (x.Language?.Name == language)
);
var item = _projectRepository
.GetItems(new[] { contentLink.ToReferenceWithoutVersion() })
.Where(x => x.ProjectID == projectId && x.Language.Name == language)
.FirstOrDefault();
return item?.ContentLink;
}

0 comments on commit 19291df

Please sign in to comment.