Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ReadOnly Session when indixing content items #15216

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AzureAISearchIndexingService
private readonly IIndexingTaskManager _indexingTaskManager;
private readonly AzureAISearchIndexSettingsService _azureAISearchIndexSettingsService;
private readonly AzureAIIndexDocumentManager _indexDocumentManager;
private readonly ISession _session;
private readonly IStore _store;
private readonly IContentManager _contentManager;
private readonly IEnumerable<IContentItemIndexHandler> _contentItemIndexHandlers;
private readonly ILogger _logger;
Expand All @@ -30,15 +30,15 @@ public AzureAISearchIndexingService(
IIndexingTaskManager indexingTaskManager,
AzureAISearchIndexSettingsService azureAISearchIndexSettingsService,
AzureAIIndexDocumentManager indexDocumentManager,
ISession session,
IStore store,
IContentManager contentManager,
IEnumerable<IContentItemIndexHandler> contentItemIndexHandlers,
ILogger<AzureAISearchIndexingService> logger)
{
_indexingTaskManager = indexingTaskManager;
_azureAISearchIndexSettingsService = azureAISearchIndexSettingsService;
_indexDocumentManager = indexDocumentManager;
_session = session;
_store = store;
_contentManager = contentManager;
_contentItemIndexHandlers = contentItemIndexHandlers;
_logger = logger;
Expand Down Expand Up @@ -81,6 +81,7 @@ public async Task ProcessContentItemsAsync(params string[] indexNames)
var tasks = new List<IndexingTask>();

var allContentTypes = indexSettings.SelectMany(x => x.IndexedContentTypes ?? []).Distinct().ToList();
var readOnlySession = _store.CreateSession(withTracking: false);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe session for simplicity

Copy link
Member Author

Choose a reason for hiding this comment

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

no. I purposely called it readOnlySession to indicate that it is a session for read only.


while (tasks.Count <= _batchSize)
{
Expand All @@ -107,25 +108,15 @@ public async Task ProcessContentItemsAsync(params string[] indexNames)

if (indexSettings.Any(x => !x.IndexLatest))
{
var publishedContentItems = await _session.Query<ContentItem, ContentItemIndex>(index => index.Published && index.ContentType.IsIn(allContentTypes) && index.ContentItemId.IsIn(updatedContentItemIds)).ListAsync();
var publishedContentItems = await readOnlySession.Query<ContentItem, ContentItemIndex>(index => index.Published && index.ContentType.IsIn(allContentTypes) && index.ContentItemId.IsIn(updatedContentItemIds)).ListAsync();
allPublished = publishedContentItems.DistinctBy(x => x.ContentItemId)
.ToDictionary(k => k.ContentItemId);

foreach (var publishedContentItem in publishedContentItems)
{
_session.Detach(publishedContentItem);
}
}

if (indexSettings.Any(x => x.IndexLatest))
{
var latestContentItems = await _session.Query<ContentItem, ContentItemIndex>(index => index.Latest && index.ContentType.IsIn(allContentTypes) && index.ContentItemId.IsIn(updatedContentItemIds)).ListAsync();
var latestContentItems = await readOnlySession.Query<ContentItem, ContentItemIndex>(index => index.Latest && index.ContentType.IsIn(allContentTypes) && index.ContentItemId.IsIn(updatedContentItemIds)).ListAsync();
allLatest = latestContentItems.DistinctBy(x => x.ContentItemId).ToDictionary(k => k.ContentItemId);

foreach (var latestContentItem in latestContentItems)
{
_session.Detach(latestContentItem);
}
}

foreach (var task in tasks)
Expand Down
Loading