Remove the "update" option from the SearchIndex page. Show improved status including records completed and expected completion time.

This commit is contained in:
j2blake 2011-11-25 20:01:04 +00:00
parent 89f753a728
commit 80c1dc9a11
3 changed files with 53 additions and 23 deletions

View file

@ -51,18 +51,15 @@ public class IndexController extends FreemarkerHttpServlet {
* SETUP -- Index is not building and nothing is requested. Solicit requests. * SETUP -- Index is not building and nothing is requested. Solicit requests.
* REFRESH -- Index is building, nothing is requested. Show continuing status. * REFRESH -- Index is building, nothing is requested. Show continuing status.
* REBUILD -- Rebuild is requested. Set the rebuild flag and show continuing status. * REBUILD -- Rebuild is requested. Set the rebuild flag and show continuing status.
* UPDATE -- Update is requested. Set the update flag and show continuing status.
* </pre> * </pre>
*/ */
private enum RequestType { private enum RequestType {
SETUP, REFRESH, REBUILD, UPDATE; SETUP, REFRESH, REBUILD;
/** What type of request is this? */ /** What type of request is this? */
static RequestType fromRequest(HttpServletRequest req) { static RequestType fromRequest(HttpServletRequest req) {
if (hasParameter(req, "rebuild")) { if (hasParameter(req, "rebuild")) {
return REBUILD; return REBUILD;
} else if (hasParameter(req, "update")) {
return UPDATE;
} else { } else {
ServletContext ctx = req.getSession().getServletContext(); ServletContext ctx = req.getSession().getServletContext();
IndexBuilder builder = IndexBuilder.getBuilder(ctx); IndexBuilder builder = IndexBuilder.getBuilder(ctx);
@ -94,7 +91,7 @@ public class IndexController extends FreemarkerHttpServlet {
@Override @Override
protected String getTitle(String siteName, VitroRequest vreq) { protected String getTitle(String siteName, VitroRequest vreq) {
return "Search Index Update or Rebuild"; return "Rebuild Search Index";
} }
@Override @Override
@ -117,10 +114,8 @@ public class IndexController extends FreemarkerHttpServlet {
switch (RequestType.fromRequest(vreq)) { switch (RequestType.fromRequest(vreq)) {
case REBUILD: case REBUILD:
builder.doIndexRebuild(); builder.doIndexRebuild();
return redirectToRefresh(body); Thread.sleep(500);
case UPDATE: return redirectToRefresh();
builder.doUpdateIndex();
return redirectToRefresh(body);
default: default:
return showCurrentStatus(builder, body); return showCurrentStatus(builder, body);
} }
@ -134,23 +129,53 @@ public class IndexController extends FreemarkerHttpServlet {
} }
} }
private ResponseValues redirectToRefresh(Map<String, Object> body) { private ResponseValues redirectToRefresh() {
return new RedirectResponseValues(PAGE_URL); return new RedirectResponseValues(PAGE_URL);
} }
private ResponseValues showCurrentStatus(IndexBuilder builder, private ResponseValues showCurrentStatus(IndexBuilder builder,
Map<String, Object> body) { Map<String, Object> body) {
WorkLevelStamp stamp = builder.getWorkLevel(); WorkLevelStamp stamp = builder.getWorkLevel();
body.put("worklevel", stamp.getLevel().toString());
WorkLevel workLevel = stamp.getLevel();
long completedCount = builder.getCompletedCount();
long totalToDo = builder.getTotalToDo();
Date since = stamp.getSince();
Date expectedCompletion = figureExpectedCompletion(since, totalToDo,
completedCount);
body.put("worklevel", workLevel.toString());
body.put("completedCount", completedCount);
body.put("totalToDo", totalToDo);
body.put("currentTask", figureCurrentTask(stamp.getFlags())); body.put("currentTask", figureCurrentTask(stamp.getFlags()));
body.put("since", stamp.getSince()); body.put("since", since);
body.put("elapsed", formatElapsedTime(stamp.getSince())); body.put("elapsed", formatElapsedTime(since, new Date()));
body.put("hasPreviousBuild", stamp.getSince().getTime() > 0L); body.put("expected", formatElapsedTime(since, expectedCompletion));
body.put("hasPreviousBuild", since.getTime() > 0L);
return new TemplateResponseValues(TEMPLATE_NAME, body); return new TemplateResponseValues(TEMPLATE_NAME, body);
} }
private String formatElapsedTime(Date since) { private Date figureExpectedCompletion(Date startTime, long totalToDo,
long elapsedMillis = System.currentTimeMillis() - since.getTime(); long completedCount) {
Date now = new Date();
long elapsedMillis = now.getTime() - startTime.getTime();
if (elapsedMillis <= 0) {
return now;
}
if (completedCount <= 0) {
return now;
}
if (totalToDo <= completedCount) {
return now;
}
long millisPerRecord = elapsedMillis / completedCount;
long expectedDuration = totalToDo * millisPerRecord;
return new Date(expectedDuration + startTime.getTime());
}
private String formatElapsedTime(Date since, Date until) {
long elapsedMillis = until.getTime() - since.getTime();
long seconds = (elapsedMillis / 1000L) % 60L; long seconds = (elapsedMillis / 1000L) % 60L;
long minutes = (elapsedMillis / 60000L) % 60L; long minutes = (elapsedMillis / 60000L) % 60L;
long hours = elapsedMillis / 3600000L; long hours = elapsedMillis / 3600000L;

View file

@ -430,6 +430,14 @@ public class IndexBuilder extends VitroBackgroundThread {
return load; return load;
} }
public long getCompletedCount() {
return IndexWorkerThread.getCount();
}
public long getTotalToDo() {
return IndexWorkerThread.getCountToIndex();
}
private static class UriLists { private static class UriLists {
private final List<String> updatedUris = new ArrayList<String>(); private final List<String> updatedUris = new ArrayList<String>();
private final List<String> deletedUris = new ArrayList<String>(); private final List<String> deletedUris = new ArrayList<String>();

View file

@ -8,20 +8,17 @@
<#if worklevel == "IDLE"> <#if worklevel == "IDLE">
<#if hasPreviousBuild??> <#if hasPreviousBuild??>
<p>Previous activity completed at ${since?string("hh:mm:ss a, MMMM dd, yyyy")}</p> <p>Most recent update was at ${since?string("hh:mm:ss a, MMMM dd, yyyy")}</p>
</#if> </#if>
<form action="${actionUrl}" method="POST"> <form action="${actionUrl}" method="POST">
<p>
<input class="submit" type="submit" name="update" value="Update" role="button" />
Add the latest changes to the index.
</p>
<p> <p>
<input class="submit" type="submit" name="rebuild" value="Rebuild" role="button" /> <input class="submit" type="submit" name="rebuild" value="Rebuild" role="button" />
Start with an empty index and build it completely. Reset the search index and re-populate it.
</p> </p>
</form> </form>
<#else> <#else>
<h3>The search index is currently being ${currentTask}.</h3> <h3>The search index is currently being ${currentTask}.</h3>
<p>since ${since?string("hh:mm:ss a, MMMM dd, yyyy")}, elapsed time ${elapsed}</p> <p>since ${since?string("hh:mm:ss a, MMMM dd, yyyy")}, elapsed time ${elapsed}, expected total time ${expected}</p>
<p>Completed ${completedCount} out of ${totalToDo} index records.</p>
</#if> </#if>