Skip to content

Commit 8222920

Browse files
committed
Proposed fix for #407 - Rewired the configuration and flow of Auto Publish functionality
1 parent e36cef7 commit 8222920

File tree

3 files changed

+25
-50
lines changed

3 files changed

+25
-50
lines changed

src/SharedAssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[assembly: AssemblyProduct("Unicorn")]
66
[assembly: ComVisible(false)]
7-
[assembly: AssemblyVersion("4.1.5.0")]
8-
[assembly: AssemblyFileVersion("4.1.5.0")]
9-
[assembly: AssemblyInformationalVersion("4.1.5")]
7+
[assembly: AssemblyVersion("4.1.6.0")]
8+
[assembly: AssemblyFileVersion("4.1.6.0")]
9+
[assembly: AssemblyInformationalVersion("4.1.6-pre1")]
1010
[assembly: CLSCompliant(false)]

src/Unicorn/Publishing/ManualPublishQueueHandler.cs

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ namespace Unicorn.Publishing
1818
public class ManualPublishQueueHandler : PublishProcessor
1919
{
2020
private static readonly ConcurrentQueue<ID> ManuallyAddedCandidates = new ConcurrentQueue<ID>();
21-
protected static bool UsePublishManager = Settings.GetBoolSetting("Unicorn.UsePublishManager", true);
22-
protected static bool UsePublishingService = Settings.GetBoolSetting("Unicorn.UsePublishingService", false);
23-
protected static int PublishingServiceMaxItemsToQueue = Settings.GetIntSetting("Unicorn.PublishingServiceMaxItemsToQueue", 50);
21+
protected static bool LegacyPublishing = Settings.GetBoolSetting("Unicorn.LegacyPublishing", false);
22+
protected static int MaxItemsToQueue = Settings.GetIntSetting("Unicorn.MaxItemsToQueue", 50);
2423

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

38-
if (!UsePublishingService)
37+
if (LegacyPublishing)
3938
{
4039
foreach (var database in targets)
4140
{
4241
logger?.Debug($"> Publishing {ManuallyAddedCandidates.Count} synced item{suffix} in queue to {database.Name}");
43-
var publishOptions = new PublishOptions(triggerItem.Database, database, PublishMode.SingleItem, triggerItem.Language, DateTime.UtcNow) { RootItem = triggerItem, CompareRevisions = compareRevisions, RepublishAll = true };
44-
if (UsePublishManager)
45-
{
46-
// this works much faster then `new Publisher(publishOptions, triggerItem.Database.Languages).PublishWithResult();`
47-
var handle = PublishManager.Publish(new PublishOptions[] { publishOptions });
48-
var publishingSucces = PublishManager.WaitFor(handle);
49-
50-
if (publishingSucces)
51-
{
52-
logger?.Debug($"> Published synced item{suffix} to {database.Name}. Statistics is not retrievable when Publish Manager is used (see setting Unicorn.UsePublishManager comments).");
53-
}
54-
else
55-
{
56-
logger?.Error($"> Error happened during publishing. Check Sitecore logs for details.");
57-
}
58-
59-
}
60-
else
61-
{
62-
var result = new Publisher(publishOptions, triggerItem.Database.Languages).PublishWithResult();
63-
64-
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})");
65-
}
42+
var publishOptions = new PublishOptions(triggerItem.Database, database, PublishMode.SingleItem, triggerItem.Language, DateTime.UtcNow) {RootItem = triggerItem, CompareRevisions = compareRevisions, RepublishAll = true};
43+
var result = new Publisher(publishOptions, triggerItem.Database.Languages).PublishWithResult();
44+
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})");
6645
}
67-
}
68-
else
46+
}
47+
else
6948
{
7049
var counter = 0;
7150
var triggerItemDatabase = triggerItem.Database;
7251
var deepModePublish = false;
7352
var publishRelatedItems = false;
7453

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

77-
if (ManuallyAddedCandidates.Count <= PublishingServiceMaxItemsToQueue)
56+
if (ManuallyAddedCandidates.Count <= MaxItemsToQueue)
7857
{
79-
// using publishing service to manually queue items in publishing service
58+
logger?.Debug($"Processing queue 1-by-1 since queue is {ManuallyAddedCandidates.Count} and Unicorn.MaxItemsToQueue is {MaxItemsToQueue}");
59+
8060
while (ManuallyAddedCandidates.Count > 0)
8161
{
8262
ID itemId;
@@ -89,14 +69,11 @@ public static bool PublishQueuedItems(Item triggerItem, Database[] targets, ILog
8969
PublishManager.PublishItem(publishCandidateItem, targets, triggerItemDatabase.Languages, deepModePublish, compareRevisions, publishRelatedItems);
9070
}
9171
}
92-
93-
logger?.Debug($"> Queued {counter} synced item{suffix} in publishing service.");
9472
}
9573
else
9674
{
97-
// we have more than maxItemsToQueue
75+
logger?.Debug($"Executing system-wide Smart Publish since queue {ManuallyAddedCandidates.Count} and Unicorn.MaxItemsToQueue is {MaxItemsToQueue}");
9876
PublishManager.PublishSmart(triggerItemDatabase, targets, triggerItemDatabase.Languages);
99-
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.");
10077
}
10178
}
10279

src/Unicorn/Standard Config Files/Unicorn.AutoPublish.config

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,17 @@
3939
</publish>
4040
</pipelines>
4141
<settings>
42-
<!--
43-
Unicorn will use Publish Manager for items publishing, which routes items publishing through Sitecore publishing service, in case it is used.
44-
Default value is true (if not specified). This setting is required for Sitecore versions lower then 8
42+
<!--
43+
Enable legacy publishing if you're on an older Sitecore release from before the PublishManager API was published
4544
-->
46-
<setting name="Unicorn.UsePublishManager" value="true" />
47-
<!--
48-
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.
49-
-->
50-
<setting name="Unicorn.UsePublishingService" value="false" />
51-
<!--
52-
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.
45+
<setting name="Unicorn.LegacyPublishing" value="false" />
46+
47+
<!--
48+
Max number of items that will be processed individually by the publishing code.
49+
If number of changed items in a sync operation goes > MaxItemsToQueue, a system Smart Publish will be executed instead
50+
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
5351
-->
54-
<setting name="Unicorn.PublishingServiceMaxItemsToQueue" value="50" />
52+
<setting name="Unicorn.MaxItemsToQueue" value="1000" />
5553
</settings>
5654
</sitecore>
5755
</configuration>

0 commit comments

Comments
 (0)