Commit e074c44c authored by Liang Ding's avatar Liang Ding

Merge pull request #51 from 88250/master

#16
parents 707d008b ded32103
......@@ -15,12 +15,10 @@
*/
package org.b3log.solo.processor;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.b3log.latke.Latkes;
import org.b3log.latke.RuntimeEnv;
import org.b3log.latke.action.AbstractCacheablePageAction;
import org.b3log.latke.annotation.RequestProcessing;
import org.b3log.latke.annotation.RequestProcessor;
......@@ -31,6 +29,7 @@ import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.servlet.renderer.DoNothingRenderer;
import org.b3log.latke.util.CollectionUtils;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.PageTypes;
import org.b3log.solo.model.Statistic;
......@@ -54,7 +53,7 @@ import org.json.JSONObject;
* <p>
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.1.5, May 31, 2012
* @version 1.0.1.7, Jul 24, 2012
* @since 0.4.0
*/
@RequestProcessor
......@@ -76,6 +75,10 @@ public final class StatProcessor {
* Language service.
*/
private LangPropsService langPropsService = LangPropsService.getInstance();
/**
* Flush size.
*/
private static final int FLUSH_SIZE = 30;
/**
* Online visitor count refresher.
......@@ -117,7 +120,17 @@ public final class StatProcessor {
statisticRepository.update(Statistic.STATISTIC, statistic);
// For article view counter
final Set<String> cachedPageKeys = PageCaches.getKeys();
final Set<String> keys = PageCaches.getKeys();
final List<String> keyList = new ArrayList<String>(keys);
final int size = keys.size() > FLUSH_SIZE ? FLUSH_SIZE : keys.size(); // Flush FLUSH_SIZE articles at most
final List<Integer> idx = CollectionUtils.getRandomIntegers(0, keys.size(), size);
final Set<String> cachedPageKeys = new HashSet<String>();
for (final Integer i : idx) {
cachedPageKeys.add(keyList.get(i));
}
for (final String cachedPageKey : cachedPageKeys) {
final JSONObject cachedPage = PageCaches.get(cachedPageKey);
if (null == cachedPage) {
......@@ -131,11 +144,6 @@ public final class StatProcessor {
}
final int hitCount = cachedPage.optInt(PageCaches.CACHED_HIT_COUNT);
if (2 > hitCount && RuntimeEnv.GAE == Latkes.getRuntimeEnv()) {
// Skips for view count tiny-changes, reduces Datastore Write Quota for Solo GAE version
continue;
}
final String articleId = cachedPage.optString(AbstractCacheablePageAction.CACHED_OID);
final JSONObject article = articleRepository.get(articleId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment