asalamon74 commented on a change in pull request #326:
URL: https://github.com/apache/solr/pull/326#discussion_r722222230



##########
File path: solr/core/src/java/org/apache/solr/core/SolrCore.java
##########
@@ -491,22 +490,27 @@ public long getIndexSize() {
   }
 
   public long getCachedIndexSize() {
-    if (indexSize.get() == null) {
-      if (log.isDebugEnabled()) {
-        log.debug("Recalculating index size for {}", getName());
+    SolrRequestInfo requestInfo = SolrRequestInfo.getRequestInfo();
+    if (requestInfo != null) {
+      Map<Object,Object> contextMap = requestInfo.getReq().getContext();
+      Long cachedIndexSize = 
(Long)contextMap.get(cachedIndexSizeKeyName(getName()));
+      if (cachedIndexSize == null) {
+        if (log.isDebugEnabled()) {
+          log.debug("Recalculating index size for {}", getName());
+        }
+        cachedIndexSize = getIndexSize();
+        contextMap.put(cachedIndexSizeKeyName(getName()), cachedIndexSize);
+      } else if (log.isDebugEnabled()) {
+        log.debug("reusing previous index size for {}", getName());
       }
-      indexSize.set(getIndexSize());
-    } else if (log.isDebugEnabled()) {
-      log.debug("reusing previous index size for {}", getName());
+      return cachedIndexSize;
+    } else {
+      return getIndexSize();
     }
-    return indexSize.get();
   }
 
-  public void clearIndexSizeCache() {
-    if (log.isDebugEnabled()) {
-      log.debug("Clearing index size cache for {}", getName());
-    }
-    indexSize.remove();
+  private String cachedIndexSizeKeyName(String name) {

Review comment:
       Yes, adding a new map is nicer but it's probably an overkill here. I'll 
add a comment, that will help.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to