Files
Umbraco-CMS/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotServiceEventHandler.cs

156 lines
6.9 KiB
C#
Raw Normal View History

using System;
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.Changes;
using Umbraco.Cms.Core.Services.Notifications;
using Umbraco.Cms.Infrastructure.PublishedCache.Persistence;
using Umbraco.Extensions;
namespace Umbraco.Cms.Infrastructure.PublishedCache
{
2020-12-21 16:44:50 +11:00
/// <summary>
/// Subscribes to Umbraco events to ensure nucache remains consistent with the source data
/// </summary>
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public class PublishedSnapshotServiceEventHandler :
IDisposable,
INotificationHandler<LanguageSavedNotification>,
INotificationHandler<MemberDeletingNotification>,
INotificationHandler<ContentRefreshNotification>,
INotificationHandler<MediaRefreshNotification>,
INotificationHandler<MemberRefreshNotification>,
INotificationHandler<ContentTypeRefreshedNotification>,
INotificationHandler<MediaTypeRefreshedNotification>,
INotificationHandler<MemberTypeRefreshedNotification>,
INotificationHandler<ScopedEntityRemoveNotification>
{
private readonly IRuntimeState _runtime;
private bool _disposedValue;
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly INuCacheContentService _publishedContentService;
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
private readonly IContentService _contentService;
private readonly IMediaService _mediaService;
2020-12-21 16:44:50 +11:00
/// <summary>
/// Initializes a new instance of the <see cref="PublishedSnapshotServiceEventHandler"/> class.
/// </summary>
public PublishedSnapshotServiceEventHandler(
IRuntimeState runtime,
IPublishedSnapshotService publishedSnapshotService,
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
INuCacheContentService publishedContentService,
IContentService contentService,
IMediaService mediaService)
{
_runtime = runtime;
_publishedSnapshotService = publishedSnapshotService;
_publishedContentService = publishedContentService;
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
_contentService = contentService;
_mediaService = mediaService;
}
2020-12-21 16:44:50 +11:00
/// <summary>
/// Binds to the Umbraco events
/// </summary>
/// <returns>Returns true if binding occurred</returns>
public bool Initialize()
{
// however, the cache is NOT available until we are configured, because loading
// content (and content types) from database cannot be consistent (see notes in "Handle
// Notifications" region), so
// - notifications will be ignored
// - trying to obtain a published snapshot from the service will throw
if (_runtime.Level != RuntimeLevel.Run)
{
return false;
}
return true;
}
// note: if the service is not ready, ie _isReady is false, then we still handle repository events,
// because we can, we do not need a working published snapshot to do it - the only reason why it could cause an
// issue is if the database table is not ready, but that should be prevented by migrations.
// we need them to be "repository" events ie to trigger from within the repository transaction,
// because they need to be consistent with the content that is being refreshed/removed - and that
// should be guaranteed by a DB transaction
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public void Handle(ScopedEntityRemoveNotification notification) =>
_publishedContentService.DeleteContentItem(notification.Entity);
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public void Handle(MemberDeletingNotification notification) => _publishedContentService.DeleteContentItems(notification.DeletedEntities);
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public void Handle(MemberRefreshNotification notification) => _publishedContentService.RefreshEntity(notification.Entity);
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public void Handle(MediaRefreshNotification notification) => _publishedContentService.RefreshEntity(notification.Entity);
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public void Handle(ContentRefreshNotification notification) => _publishedContentService.RefreshContent(notification.Entity);
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public void Handle(ContentTypeRefreshedNotification notification)
{
const ContentTypeChangeTypes types // only for those that have been refreshed
= ContentTypeChangeTypes.RefreshMain | ContentTypeChangeTypes.RefreshOther;
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
var contentTypeIds = notification.Changes.Where(x => x.ChangeTypes.HasTypesAny(types)).Select(x => x.Item.Id).ToArray();
if (contentTypeIds.Any())
{
_publishedSnapshotService.Rebuild(contentTypeIds: contentTypeIds);
}
}
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public void Handle(MediaTypeRefreshedNotification notification)
{
const ContentTypeChangeTypes types // only for those that have been refreshed
= ContentTypeChangeTypes.RefreshMain | ContentTypeChangeTypes.RefreshOther;
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
var mediaTypeIds = notification.Changes.Where(x => x.ChangeTypes.HasTypesAny(types)).Select(x => x.Item.Id).ToArray();
if (mediaTypeIds.Any())
{
_publishedSnapshotService.Rebuild(mediaTypeIds: mediaTypeIds);
}
}
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public void Handle(MemberTypeRefreshedNotification notification)
{
const ContentTypeChangeTypes types // only for those that have been refreshed
= ContentTypeChangeTypes.RefreshMain | ContentTypeChangeTypes.RefreshOther;
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
var memberTypeIds = notification.Changes.Where(x => x.ChangeTypes.HasTypesAny(types)).Select(x => x.Item.Id).ToArray();
if (memberTypeIds.Any())
{
_publishedSnapshotService.Rebuild(memberTypeIds: memberTypeIds);
}
}
2021-03-25 14:51:00 +01:00
// TODO: This should be a cache refresher call!
/// <summary>
2020-12-22 13:49:26 +11:00
/// If a <see cref="ILanguage"/> is ever saved with a different culture, we need to rebuild all of the content nucache database table
/// </summary>
2021-03-25 14:51:00 +01:00
public void Handle(LanguageSavedNotification notification)
{
// culture changed on an existing language
2021-03-25 14:51:00 +01:00
var cultureChanged = notification.SavedEntities.Any(x => !x.WasPropertyDirty(nameof(ILanguage.Id)) && x.WasPropertyDirty(nameof(ILanguage.IsoCode)));
if (cultureChanged)
{
2020-12-22 13:49:26 +11:00
// Rebuild all content for all content types
_publishedSnapshotService.Rebuild(contentTypeIds: Array.Empty<int>());
}
}
protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
_disposedValue = true;
}
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}