Skip to content

Commit dd3dae0

Browse files
authored
Merge pull request #287 from umbraco/bugfix/v16/algolia-load-balancing
Update V16 with changes for load balancing environments and converters
2 parents c72deb1 + 13fb582 commit dd3dae0

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

src/Umbraco.Cms.Integrations.Search.Algolia/AlgoliaComposer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void Compose(IUmbracoBuilder builder)
2424
builder.AddNotificationHandler<UmbracoApplicationStartingNotification, RunAlgoliaIndicesMigration>();
2525

2626
builder.AddNotificationAsyncHandler<ContentCacheRefresherNotification, AlgoliaContentCacheRefresherHandler>();
27+
builder.AddNotificationAsyncHandler<ContentPublishedNotification, AlgoliaContentPublishedHandler>();
2728

2829
builder.Services.AddOptions<AlgoliaSettings>()
2930
.Bind(builder.Config.GetSection(Constants.SettingsPath));

src/Umbraco.Cms.Integrations.Search.Algolia/Client/public/umbraco-package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "Umbraco.Cms.Integrations.Search.Algolia",
33
"name": "Umbraco CMS Integrations: Search - Algolia",
4-
"version": "5.0.0",
4+
"version": "5.0.2",
55
"extensions": [
66
{
77
"name": "Umbraco EntryPoint",

src/Umbraco.Cms.Integrations.Search.Algolia/Converters/UmbracoMediaPickerConverter.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Umbraco.Cms.Integrations.Search.Algolia.Converters
77
{
88
public class UmbracoMediaPickerConverter : IAlgoliaIndexValueConverter
99
{
10+
const string udiPrefix = "umb://media/";
11+
1012
private readonly IMediaService _mediaService;
1113

1214
public UmbracoMediaPickerConverter(IMediaService mediaService) => _mediaService = mediaService;
@@ -21,19 +23,34 @@ public object ParseIndexValues(IProperty property, IndexValue indexValue)
2123

2224
if (string.IsNullOrEmpty(parsedIndexValue)) return list;
2325

24-
var inputMedia = JsonSerializer.Deserialize<IEnumerable<MediaItem>>(parsedIndexValue);
26+
if (parsedIndexValue.StartsWith(udiPrefix))
27+
{
28+
var guidPart = parsedIndexValue.Substring(udiPrefix.Length);
29+
if (Guid.TryParse(guidPart, out Guid guid))
30+
{
31+
var mediaItem = _mediaService.GetById(guid);
32+
if (mediaItem != null)
33+
{
34+
list.Add(mediaItem.GetValue("umbracoFile")?.ToString() ?? string.Empty);
35+
}
36+
}
37+
}
38+
else
39+
{
40+
var inputMedia = JsonSerializer.Deserialize<IEnumerable<MediaItem>>(parsedIndexValue);
2541

26-
if (inputMedia == null) return string.Empty;
42+
if (inputMedia == null) return string.Empty;
2743

28-
foreach (var item in inputMedia)
29-
{
30-
if (item == null) continue;
44+
foreach (var item in inputMedia)
45+
{
46+
if (item == null) continue;
3147

32-
var mediaItem = _mediaService.GetById(Guid.Parse(item.MediaKey));
48+
var mediaItem = _mediaService.GetById(Guid.Parse(item.MediaKey));
3349

34-
if (mediaItem == null) continue;
50+
if (mediaItem == null) continue;
3551

36-
list.Add(mediaItem.GetValue("umbracoFile")?.ToString() ?? string.Empty);
52+
list.Add(mediaItem.GetValue("umbracoFile")?.ToString() ?? string.Empty);
53+
}
3754
}
3855

3956
return list;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Umbraco.Cms.Core.Cache;
2+
using Umbraco.Cms.Core.Events;
3+
using Umbraco.Cms.Core.Notifications;
4+
using Umbraco.Cms.Core.Sync;
5+
using Umbraco.Extensions;
6+
7+
namespace Umbraco.Cms.Integrations.Search.Algolia.Handlers
8+
{
9+
public class AlgoliaContentPublishedHandler : INotificationAsyncHandler<ContentPublishedNotification>
10+
{
11+
private readonly IServerRoleAccessor _serverRoleAccessor;
12+
private readonly DistributedCache _distributedCache;
13+
14+
public AlgoliaContentPublishedHandler(
15+
IServerRoleAccessor serverRoleAccessor,
16+
DistributedCache distributedCache)
17+
{
18+
_serverRoleAccessor = serverRoleAccessor;
19+
_distributedCache = distributedCache;
20+
}
21+
22+
public Task HandleAsync(ContentPublishedNotification notification, CancellationToken cancellationToken)
23+
{
24+
if (_serverRoleAccessor.CurrentServerRole == ServerRole.SchedulingPublisher)
25+
{
26+
_distributedCache.RefreshAllContentCache();
27+
}
28+
return Task.CompletedTask;
29+
}
30+
}
31+
}

src/Umbraco.Cms.Integrations.Search.Algolia/Umbraco.Cms.Integrations.Search.Algolia.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageIconUrl></PackageIconUrl>
1616
<PackageProjectUrl>https://github.com/umbraco/Umbraco.Cms.Integrations/tree/main/src/Umbraco.Cms.Integrations.Search.Algolia</PackageProjectUrl>
1717
<RepositoryUrl>https://github.com/umbraco/Umbraco.Cms.Integrations</RepositoryUrl>
18-
<Version>5.0.1</Version>
18+
<Version>5.0.2</Version>
1919
<Authors>Umbraco HQ</Authors>
2020
<Company>Umbraco</Company>
2121
<PackageTags>Umbraco;Umbraco-Marketplace</PackageTags>

0 commit comments

Comments
 (0)