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')
|
'Failed to check index processing')
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
|
|
||||||
if (data) {
|
if (data !== null && data !== "null") {
|
||||||
|
|
||||||
//copy all resulting properties
|
//copy all resulting properties
|
||||||
for (var k in data) {
|
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. " +
|
"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 " +
|
"It is not recommended to rebuild an index during times of high website traffic " +
|
||||||
"or when editors are editing content.")) {
|
"or when editors are editing content.")) {
|
||||||
|
|
||||||
indexer.isProcessing = true;
|
indexer.isProcessing = true;
|
||||||
|
indexer.processingAttempts = 0;
|
||||||
|
|
||||||
umbRequestHelper.resourcePromise(
|
umbRequestHelper.resourcePromise(
|
||||||
$http.post(umbRequestHelper.getApiUrl("examineMgmtBaseUrl", "PostRebuildIndex", { indexerName: indexer.name })),
|
$http.post(umbRequestHelper.getApiUrl("examineMgmtBaseUrl", "PostRebuildIndex", { indexerName: indexer.name })),
|
||||||
|
|||||||
@@ -164,12 +164,23 @@ namespace Umbraco.Web.WebServices
|
|||||||
var msg = ValidateLuceneIndexer(indexerName, out indexer);
|
var msg = ValidateLuceneIndexer(indexerName, out indexer);
|
||||||
if (msg.IsSuccessStatusCode)
|
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
|
try
|
||||||
{
|
{
|
||||||
indexer.RebuildIndex();
|
indexer.RebuildIndex();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
//ensure it's not listening
|
||||||
|
indexer.IndexOperationComplete -= Indexer_IndexOperationComplete;
|
||||||
LogHelper.Error<ExamineManagementApiController>("An error occurred rebuilding index", ex);
|
LogHelper.Error<ExamineManagementApiController>("An error occurred rebuilding index", ex);
|
||||||
var response = Request.CreateResponse(HttpStatusCode.Conflict);
|
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));
|
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;
|
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>
|
/// <summary>
|
||||||
/// Check if the index has been rebuilt
|
/// Check if the index has been rebuilt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="indexerName"></param>
|
/// <param name="indexerName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This is kind of rudimentary since there's no way we can know that the index has rebuilt, we'll just check
|
/// This is kind of rudimentary since there's no way we can know that the index has rebuilt, we
|
||||||
/// if the index is locked based on Lucene apis
|
/// 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>
|
/// </remarks>
|
||||||
public ExamineIndexerModel PostCheckRebuildIndex(string indexerName)
|
public ExamineIndexerModel PostCheckRebuildIndex(string indexerName)
|
||||||
{
|
{
|
||||||
@@ -195,9 +218,11 @@ namespace Umbraco.Web.WebServices
|
|||||||
var msg = ValidateLuceneIndexer(indexerName, out indexer);
|
var msg = ValidateLuceneIndexer(indexerName, out indexer);
|
||||||
if (msg.IsSuccessStatusCode)
|
if (msg.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var isLocked = indexer.IsIndexLocked();
|
var cacheKey = "temp_indexing_op_" + indexerName;
|
||||||
return isLocked
|
var found = ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem(cacheKey);
|
||||||
? null
|
//if its still there then it's not done
|
||||||
|
return found != null
|
||||||
|
? null
|
||||||
: CreateModel(indexer);
|
: CreateModel(indexer);
|
||||||
}
|
}
|
||||||
throw new HttpResponseException(msg);
|
throw new HttpResponseException(msg);
|
||||||
@@ -239,13 +264,24 @@ namespace Umbraco.Web.WebServices
|
|||||||
}
|
}
|
||||||
|
|
||||||
var luceneIndexer = indexer as LuceneIndexer;
|
var luceneIndexer = indexer as LuceneIndexer;
|
||||||
if (luceneIndexer != null && luceneIndexer.IndexExists())
|
if (luceneIndexer != null)
|
||||||
{
|
{
|
||||||
indexerModel.IsLuceneIndex = true;
|
indexerModel.IsLuceneIndex = true;
|
||||||
indexerModel.DocumentCount = luceneIndexer.GetIndexDocumentCount();
|
|
||||||
indexerModel.FieldCount = luceneIndexer.GetIndexFieldCount();
|
if (luceneIndexer.IndexExists())
|
||||||
indexerModel.IsOptimized = luceneIndexer.IsIndexOptimized();
|
{
|
||||||
indexerModel.DeletionCount = luceneIndexer.GetDeletedDocumentsCount();
|
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;
|
return indexerModel;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user