Fixes: U4-6891 Can't get to the "Rebuild" button when Lucene index folder is empty as well as how the polling works.
This commit is contained in:
@@ -10,7 +10,7 @@ function examineMgmtController($scope, umbRequestHelper, $log, $http, $q, $timeo
|
||||
'Failed to check index processing')
|
||||
.then(function(data) {
|
||||
|
||||
if (data) {
|
||||
if (data !== null && data !== "null") {
|
||||
|
||||
//copy all resulting properties
|
||||
for (var k in data) {
|
||||
@@ -67,7 +67,9 @@ function examineMgmtController($scope, umbRequestHelper, $log, $http, $q, $timeo
|
||||
"Depending on how much content there is in your site this could take a while. " +
|
||||
"It is not recommended to rebuild an index during times of high website traffic " +
|
||||
"or when editors are editing content.")) {
|
||||
|
||||
indexer.isProcessing = true;
|
||||
indexer.processingAttempts = 0;
|
||||
|
||||
umbRequestHelper.resourcePromise(
|
||||
$http.post(umbRequestHelper.getApiUrl("examineMgmtBaseUrl", "PostRebuildIndex", { indexerName: indexer.name })),
|
||||
|
||||
@@ -164,12 +164,23 @@ namespace Umbraco.Web.WebServices
|
||||
var msg = ValidateLuceneIndexer(indexerName, out indexer);
|
||||
if (msg.IsSuccessStatusCode)
|
||||
{
|
||||
//remove it in case there's a handler there alraedy
|
||||
indexer.IndexOperationComplete -= Indexer_IndexOperationComplete;
|
||||
//now add a single handler
|
||||
indexer.IndexOperationComplete += Indexer_IndexOperationComplete;
|
||||
|
||||
var cacheKey = "temp_indexing_op_" + indexer.Name;
|
||||
//put temp val in cache which is used as a rudimentary way to know when the indexing is done
|
||||
ApplicationContext.ApplicationCache.RuntimeCache.InsertCacheItem(cacheKey, () => "tempValue", TimeSpan.FromMinutes(5), isSliding: false);
|
||||
|
||||
try
|
||||
{
|
||||
indexer.RebuildIndex();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//ensure it's not listening
|
||||
indexer.IndexOperationComplete -= Indexer_IndexOperationComplete;
|
||||
LogHelper.Error<ExamineManagementApiController>("An error occurred rebuilding index", ex);
|
||||
var response = Request.CreateResponse(HttpStatusCode.Conflict);
|
||||
response.Content = new StringContent(string.Format("The index could not be rebuilt at this time, most likely there is another thread currently writing to the index. Error: {0}", ex));
|
||||
@@ -180,14 +191,26 @@ namespace Umbraco.Web.WebServices
|
||||
return msg;
|
||||
}
|
||||
|
||||
//static listener so it's not GC'd
|
||||
private static void Indexer_IndexOperationComplete(object sender, EventArgs e)
|
||||
{
|
||||
var indexer = (LuceneIndexer) sender;
|
||||
|
||||
//ensure it's not listening anymore
|
||||
indexer.IndexOperationComplete -= Indexer_IndexOperationComplete;
|
||||
|
||||
var cacheKey = "temp_indexing_op_" + indexer.Name;
|
||||
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(cacheKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the index has been rebuilt
|
||||
/// </summary>
|
||||
/// <param name="indexerName"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This is kind of rudimentary since there's no way we can know that the index has rebuilt, we'll just check
|
||||
/// if the index is locked based on Lucene apis
|
||||
/// This is kind of rudimentary since there's no way we can know that the index has rebuilt, we
|
||||
/// have a listener for the index op complete so we'll just check if that key is no longer there in the runtime cache
|
||||
/// </remarks>
|
||||
public ExamineIndexerModel PostCheckRebuildIndex(string indexerName)
|
||||
{
|
||||
@@ -195,9 +218,11 @@ namespace Umbraco.Web.WebServices
|
||||
var msg = ValidateLuceneIndexer(indexerName, out indexer);
|
||||
if (msg.IsSuccessStatusCode)
|
||||
{
|
||||
var isLocked = indexer.IsIndexLocked();
|
||||
return isLocked
|
||||
? null
|
||||
var cacheKey = "temp_indexing_op_" + indexerName;
|
||||
var found = ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem(cacheKey);
|
||||
//if its still there then it's not done
|
||||
return found != null
|
||||
? null
|
||||
: CreateModel(indexer);
|
||||
}
|
||||
throw new HttpResponseException(msg);
|
||||
@@ -239,13 +264,24 @@ namespace Umbraco.Web.WebServices
|
||||
}
|
||||
|
||||
var luceneIndexer = indexer as LuceneIndexer;
|
||||
if (luceneIndexer != null && luceneIndexer.IndexExists())
|
||||
if (luceneIndexer != null)
|
||||
{
|
||||
indexerModel.IsLuceneIndex = true;
|
||||
indexerModel.DocumentCount = luceneIndexer.GetIndexDocumentCount();
|
||||
indexerModel.FieldCount = luceneIndexer.GetIndexFieldCount();
|
||||
indexerModel.IsOptimized = luceneIndexer.IsIndexOptimized();
|
||||
indexerModel.DeletionCount = luceneIndexer.GetDeletedDocumentsCount();
|
||||
|
||||
if (luceneIndexer.IndexExists())
|
||||
{
|
||||
indexerModel.DocumentCount = luceneIndexer.GetIndexDocumentCount();
|
||||
indexerModel.FieldCount = luceneIndexer.GetIndexFieldCount();
|
||||
indexerModel.IsOptimized = luceneIndexer.IsIndexOptimized();
|
||||
indexerModel.DeletionCount = luceneIndexer.GetDeletedDocumentsCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
indexerModel.DocumentCount = 0;
|
||||
indexerModel.FieldCount = 0;
|
||||
indexerModel.IsOptimized = true;
|
||||
indexerModel.DeletionCount = 0;
|
||||
}
|
||||
}
|
||||
return indexerModel;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user