Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js

Issue 113293007: [Files.app] Change sort timing during metadata fetch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js
diff --git a/chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js b/chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js
index 75dabec132323901386012c85aa231ec7e35a55c..8ceeb96be3f4d96c50867c31d3c2a79ff5268f5c 100644
--- a/chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js
+++ b/chrome/browser/resources/file_manager/foreground/js/metadata/metadata_cache.js
@@ -77,6 +77,8 @@ function MetadataCache() {
this.batchCount_ = 0;
this.totalCount_ = 0;
+ this.currentContentNumber_ = 0;
+
/**
* Time of first get query of the current batch. Items updated later than this
* will not be evicted.
@@ -159,6 +161,27 @@ MetadataCache.prototype.isInitialized = function() {
};
/**
+ * Sets the number of contents currently shown.
+ * @param {number} number The number of the contents currently shown.
+ **/
+MetadataCache.prototype.setCurrentContentNumber = function(number) {
+ this.currentContentNumber_ = number;
+
+ if (this.totalCount_ > this.currentEvictionNumber_())
+ this.evict_();
+};
+
+/**
+ * Returns the current threshold to evict caches. When the number of caches
+ * exceeds this, the cache should be evicted.
+ * @return {number} Threshold to evict caches.
+ * @private
+ */
+MetadataCache.prototype.currentEvictionThreshold_ = function() {
+ return this.currentContentNumber_ * 2 + MetadataCache.EVICTION_NUMBER / 2;
+};
+
+/**
* Fetches the metadata, puts it in the cache, and passes to callback.
* If required metadata is already in the cache, does not fetch it again.
* @param {string|Entry|Array.<string|Entry>} items The list of entries or
@@ -456,7 +479,7 @@ MetadataCache.prototype.startBatchUpdates = function() {
MetadataCache.prototype.endBatchUpdates = function() {
this.batchCount_--;
if (this.batchCount_ != 0) return;
- if (this.totalCount_ > MetadataCache.EVICTION_NUMBER)
+ if (this.totalCount_ > this.currentEvictionThreshold_())
this.evict_();
for (var index = 0; index < this.observers_.length; index++) {
var observer = this.observers_[index];
@@ -504,7 +527,7 @@ MetadataCache.prototype.evict_ = function() {
var toRemove = [];
// We leave only a half of items, so we will not call evict_ soon again.
- var desiredCount = Math.round(MetadataCache.EVICTION_NUMBER / 2);
+ var desiredCount = Math.round(this.currentEvictionThreshold_() / 2);
var removeCount = this.totalCount_ - desiredCount;
for (var url in this.cache_) {
if (this.cache_.hasOwnProperty(url) &&

Powered by Google App Engine
This is Rietveld 408576698