-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathIndexingRebuilderService.cs
More file actions
65 lines (56 loc) · 2.07 KB
/
IndexingRebuilderService.cs
File metadata and controls
65 lines (56 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Examine;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Infrastructure.Examine;
using Umbraco.Cms.Infrastructure.Models;
namespace Umbraco.Cms.Infrastructure.Services;
/// <inheritdoc />
public class IndexingRebuilderService : IIndexingRebuilderService
{
private readonly IIndexRebuilder _indexRebuilder;
private readonly ILogger<IndexingRebuilderService> _logger;
public IndexingRebuilderService(
IIndexRebuilder indexRebuilder,
ILogger<IndexingRebuilderService> logger)
{
_indexRebuilder = indexRebuilder;
_logger = logger;
}
[Obsolete("Use the non-obsolete constructor instead. Scheduled for removal in V19.")]
public IndexingRebuilderService(
AppCaches runtimeCache,
IIndexRebuilder indexRebuilder,
ILogger<IndexingRebuilderService> logger)
{
_indexRebuilder = indexRebuilder;
_logger = logger;
}
/// <inheritdoc />
public bool CanRebuild(string indexName) => _indexRebuilder.CanRebuild(indexName);
/// <inheritdoc />
[Obsolete("Use TryRebuildAsync instead. Scheduled for removal in V19.")]
public bool TryRebuild(IIndex index, string indexName)
=> TryRebuildAsync(index, indexName).GetAwaiter().GetResult();
/// <inheritdoc />
public async Task<bool> TryRebuildAsync(IIndex index, string indexName)
{
try
{
Attempt<IndexRebuildResult> attempt = await _indexRebuilder.RebuildIndexAsync(indexName);
return attempt.Success;
}
catch (Exception exception)
{
_logger.LogError(exception, "An error occurred rebuilding index");
return false;
}
}
/// <inheritdoc />
[Obsolete("Use IsRebuildingAsync() instead. Scheduled for removal in V19.")]
public bool IsRebuilding(string indexName)
=> IsRebuildingAsync(indexName).GetAwaiter().GetResult();
/// <inheritdoc />
public Task<bool> IsRebuildingAsync(string indexName)
=> _indexRebuilder.IsRebuildingAsync(indexName);
}