Skip to content

Commit

Permalink
Merge pull request #417 from SitecoreUnicorn/develop
Browse files Browse the repository at this point in the history
Merge for 4.1.6 release
  • Loading branch information
cassidydotdk authored Oct 23, 2021
2 parents e36cef7 + 6e70002 commit e9028ac
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 52 deletions.
6 changes: 3 additions & 3 deletions src/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[assembly: AssemblyProduct("Unicorn")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("4.1.5.0")]
[assembly: AssemblyFileVersion("4.1.5.0")]
[assembly: AssemblyInformationalVersion("4.1.5")]
[assembly: AssemblyVersion("4.1.6.0")]
[assembly: AssemblyFileVersion("4.1.6.0")]
[assembly: AssemblyInformationalVersion("4.1.6")]
[assembly: CLSCompliant(false)]
2 changes: 0 additions & 2 deletions src/Unicorn/Configuration/PredicatePresetHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using Sitecore;
using Sitecore.Diagnostics;

namespace Unicorn.Configuration
{
[UsedImplicitly]
public class PredicatePresetHandler : IPredicatePresetHandler
{
// ReSharper disable once InconsistentNaming
Expand Down
49 changes: 13 additions & 36 deletions src/Unicorn/Publishing/ManualPublishQueueHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ namespace Unicorn.Publishing
public class ManualPublishQueueHandler : PublishProcessor
{
private static readonly ConcurrentQueue<ID> ManuallyAddedCandidates = new ConcurrentQueue<ID>();
protected static bool UsePublishManager = Settings.GetBoolSetting("Unicorn.UsePublishManager", true);
protected static bool UsePublishingService = Settings.GetBoolSetting("Unicorn.UsePublishingService", false);
protected static int PublishingServiceMaxItemsToQueue = Settings.GetIntSetting("Unicorn.PublishingServiceMaxItemsToQueue", 50);
protected static bool LegacyPublishing = Settings.GetBoolSetting("Unicorn.LegacyPublishing", false);
protected static int MaxItemsToQueue = Settings.GetIntSetting("Unicorn.MaxItemsToQueue", 50);

public static void AddItemToPublish(Guid itemId)
{
Expand All @@ -35,48 +34,29 @@ public static bool PublishQueuedItems(Item triggerItem, Database[] targets, ILog
var suffix = ManuallyAddedCandidates.Count == 1 ? string.Empty : "s";
var compareRevisions = false;

if (!UsePublishingService)
if (LegacyPublishing)
{
foreach (var database in targets)
{
logger?.Debug($"> Publishing {ManuallyAddedCandidates.Count} synced item{suffix} in queue to {database.Name}");
var publishOptions = new PublishOptions(triggerItem.Database, database, PublishMode.SingleItem, triggerItem.Language, DateTime.UtcNow) { RootItem = triggerItem, CompareRevisions = compareRevisions, RepublishAll = true };
if (UsePublishManager)
{
// this works much faster then `new Publisher(publishOptions, triggerItem.Database.Languages).PublishWithResult();`
var handle = PublishManager.Publish(new PublishOptions[] { publishOptions });
var publishingSucces = PublishManager.WaitFor(handle);

if (publishingSucces)
{
logger?.Debug($"> Published synced item{suffix} to {database.Name}. Statistics is not retrievable when Publish Manager is used (see setting Unicorn.UsePublishManager comments).");
}
else
{
logger?.Error($"> Error happened during publishing. Check Sitecore logs for details.");
}

}
else
{
var result = new Publisher(publishOptions, triggerItem.Database.Languages).PublishWithResult();

logger?.Debug($"> Published synced item{suffix} to {database.Name} (New: {result.Statistics.Created}, Updated: {result.Statistics.Updated}, Deleted: {result.Statistics.Deleted} Skipped: {result.Statistics.Skipped})");
}
var publishOptions = new PublishOptions(triggerItem.Database, database, PublishMode.SingleItem, triggerItem.Language, DateTime.UtcNow) {RootItem = triggerItem, CompareRevisions = compareRevisions, RepublishAll = true};
var result = new Publisher(publishOptions, triggerItem.Database.Languages).PublishWithResult();
logger?.Debug($"> Published synced item{suffix} to {database.Name} (New: {result.Statistics.Created}, Updated: {result.Statistics.Updated}, Deleted: {result.Statistics.Deleted} Skipped: {result.Statistics.Skipped})");
}
}
else
}
else
{
var counter = 0;
var triggerItemDatabase = triggerItem.Database;
var deepModePublish = false;
var publishRelatedItems = false;

logger?.Debug($"> Queueing {ManuallyAddedCandidates.Count} synced item{suffix} in publishing service.");
logger?.Debug($"> Queueing {ManuallyAddedCandidates.Count} synced item{suffix}");

if (ManuallyAddedCandidates.Count <= PublishingServiceMaxItemsToQueue)
if (ManuallyAddedCandidates.Count <= MaxItemsToQueue)
{
// using publishing service to manually queue items in publishing service
logger?.Debug($"Processing queue 1-by-1 since queue is {ManuallyAddedCandidates.Count} and Unicorn.MaxItemsToQueue is {MaxItemsToQueue}");

while (ManuallyAddedCandidates.Count > 0)
{
ID itemId;
Expand All @@ -89,14 +69,11 @@ public static bool PublishQueuedItems(Item triggerItem, Database[] targets, ILog
PublishManager.PublishItem(publishCandidateItem, targets, triggerItemDatabase.Languages, deepModePublish, compareRevisions, publishRelatedItems);
}
}

logger?.Debug($"> Queued {counter} synced item{suffix} in publishing service.");
}
else
{
// we have more than maxItemsToQueue
logger?.Debug($"Executing system-wide Smart Publish since queue {ManuallyAddedCandidates.Count} and Unicorn.MaxItemsToQueue is {MaxItemsToQueue}");
PublishManager.PublishSmart(triggerItemDatabase, targets, triggerItemDatabase.Languages);
logger?.Debug($"> Since we have more than {PublishingServiceMaxItemsToQueue} synced items - it is counter-productive to queue them one-by-one, so we are publishing whole database to all targets.");
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/Unicorn/Standard Config Files/Unicorn.AutoPublish.config
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,17 @@
</publish>
</pipelines>
<settings>
<!--
Unicorn will use Publish Manager for items publishing, which routes items publishing through Sitecore publishing service, in case it is used.
Default value is true (if not specified). This setting is required for Sitecore versions lower then 8
<!--
Enable legacy publishing if you're on an older Sitecore release from before the PublishManager API was published
-->
<setting name="Unicorn.UsePublishManager" value="true" />
<!--
There is no uniform way to learn, if we are using publishing service or not (even setting PublishingServiceUrlRoot have changed between versions :( ). Publishing service ignores publish queue and we need to build own queue for it when building handle for PublishManager -> hence, we need a separate setting for this.
-->
<setting name="Unicorn.UsePublishingService" value="false" />
<!--
If we have synced more that items number in this setting - it is faster to queue just smart publish in Publishing service than queueing individual items.
<setting name="Unicorn.LegacyPublishing" value="false" />

<!--
Max number of items that will be processed individually by the publishing code.
If number of changed items in a sync operation goes > MaxItemsToQueue, a system Smart Publish will be executed instead
Set this value to 0 if you always want Smart Publish to happen. Set it to something silly (like 1000000) if you never want Smart Publish to happen
-->
<setting name="Unicorn.PublishingServiceMaxItemsToQueue" value="50" />
<setting name="Unicorn.MaxItemsToQueue" value="1000" />
</settings>
</sitecore>
</configuration>

0 comments on commit e9028ac

Please sign in to comment.