Commit 06be1bc7 authored by Liang Ding's avatar Liang Ding

修复浏览计数问题

parent 512b0adc
......@@ -66,7 +66,7 @@ import org.jsoup.Jsoup;
* Article processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.2.13, Oct 26, 2013
* @version 1.1.2.14, Nov 17, 2013
* @since 0.3.1
*/
@RequestProcessor
......@@ -131,6 +131,12 @@ public class ArticleProcessor {
@Inject
private ArticleMgmtService articleMgmtService;
/**
* Statistic management service.
*/
@Inject
private StatisticMgmtService statisticMgmtService;
/**
* Shows the article view password form.
*
......@@ -724,6 +730,8 @@ public class ArticleProcessor {
filler.fillBlogFooter(request, dataModel, preference);
filler.fillSide(request, dataModel, preference);
Skins.fillLangs(preference.optString(Preference.LOCALE_STRING), (String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME), dataModel);
statisticMgmtService.incBlogViewCount(request, response);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......@@ -817,6 +825,8 @@ public class ArticleProcessor {
filler.fillBlogHeader(request, response, dataModel, preference);
filler.fillBlogFooter(request, dataModel, preference);
filler.fillSide(request, dataModel, preference);
statisticMgmtService.incBlogViewCount(request, response);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......@@ -927,6 +937,8 @@ public class ArticleProcessor {
if (!Requests.hasBeenServed(request, response)) {
articleMgmtService.incViewCount(articleId);
}
statisticMgmtService.incBlogViewCount(request, response);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......
......@@ -45,6 +45,7 @@ import org.b3log.solo.model.Preference;
import org.b3log.solo.processor.renderer.ConsoleRenderer;
import org.b3log.solo.processor.util.Filler;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.StatisticMgmtService;
import org.b3log.solo.util.Skins;
import org.json.JSONObject;
......@@ -54,7 +55,7 @@ import org.json.JSONObject;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @version 1.1.1.4, Sep 11, 2013
* @version 1.1.1.5, Nov 17, 2013
* @since 0.3.1
*/
@RequestProcessor
......@@ -83,6 +84,12 @@ public class IndexProcessor {
@Inject
private LangPropsService langPropsService;
/**
* Statistic management service.
*/
@Inject
private StatisticMgmtService statisticMgmtService;
/**
* Shows index with the specified context.
*
......@@ -126,6 +133,8 @@ public class IndexProcessor {
}
dataModel.put(Common.PATH, "");
statisticMgmtService.incBlogViewCount(request, response);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......
......@@ -40,6 +40,7 @@ import org.b3log.solo.model.Preference;
import org.b3log.solo.processor.util.Filler;
import org.b3log.solo.service.CommentQueryService;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.StatisticMgmtService;
import org.b3log.solo.util.Markdowns;
import org.b3log.solo.util.Skins;
import org.json.JSONObject;
......@@ -49,7 +50,7 @@ import org.json.JSONObject;
* Page processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.3, Oct 14, 2013
* @version 1.1.0.4, Nov 17, 2013
* @since 0.3.1
*/
@RequestProcessor
......@@ -84,6 +85,12 @@ public class PageProcessor {
@Inject
private CommentQueryService commentQueryService;
/**
* Statistic management service.
*/
@Inject
private StatisticMgmtService statisticMgmtService;
/**
* Shows page with the specified context.
*
......@@ -144,6 +151,8 @@ public class PageProcessor {
filler.fillSide(request, dataModel, preference);
filler.fillBlogHeader(request, response, dataModel, preference);
filler.fillBlogFooter(request, dataModel, preference);
statisticMgmtService.incBlogViewCount(request, response);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......
......@@ -48,6 +48,7 @@ import org.b3log.solo.model.Tag;
import org.b3log.solo.processor.util.Filler;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.StatisticMgmtService;
import org.b3log.solo.service.TagQueryService;
import org.b3log.solo.service.UserQueryService;
import org.b3log.solo.util.Skins;
......@@ -60,7 +61,7 @@ import org.json.JSONObject;
* Tag processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.1.2, Oct 29, 2013
* @version 1.1.1.3, Nov 17, 2013
* @since 0.3.1
*/
@RequestProcessor
......@@ -107,6 +108,12 @@ public class TagProcessor {
@Inject
private TagQueryService tagQueryService;
/**
* Statistic management service.
*/
@Inject
private StatisticMgmtService statisticMgmtService;
/**
* Shows articles related with a tag with the specified context.
*
......@@ -201,6 +208,8 @@ public class TagProcessor {
filler.fillSide(request, dataModel, preference);
filler.fillBlogHeader(request, response, dataModel, preference);
filler.fillBlogFooter(request, dataModel, preference);
statisticMgmtService.incBlogViewCount(request, response);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......
......@@ -38,6 +38,7 @@ import org.b3log.latke.util.freemarker.Templates;
import org.b3log.solo.model.Preference;
import org.b3log.solo.processor.util.Filler;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.StatisticMgmtService;
import org.b3log.solo.util.Skins;
import org.json.JSONObject;
......@@ -54,7 +55,7 @@ import org.json.JSONObject;
* </p>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.3, Jul 11, 2012
* @version 1.0.0.4, Nov 17, 2013
* @since 0.4.5
*/
@RequestProcessor
......@@ -83,6 +84,12 @@ public class UserTemplateProcessor {
@Inject
private LangPropsService langPropsService;
/**
* Statistic management service.
*/
@Inject
private StatisticMgmtService statisticMgmtService;
/**
* Shows the user template page.
*
......@@ -129,6 +136,8 @@ public class UserTemplateProcessor {
filler.fillUserTemplate(request, template, dataModel, preference);
filler.fillBlogFooter(request, dataModel, preference);
Skins.fillLangs(preference.optString(Preference.LOCALE_STRING), (String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME), dataModel);
statisticMgmtService.incBlogViewCount(request, response);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
......
......@@ -32,7 +32,7 @@ import org.b3log.solo.SoloServletListener;
* renderer for administrator console and initialization rendering.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Mar 29, 2012
* @version 1.0.0.1, Nov 17, 2013
* @since 0.4.1
*/
public final class ConsoleRenderer extends AbstractFreeMarkerRenderer {
......@@ -60,9 +60,12 @@ public final class ConsoleRenderer extends AbstractFreeMarkerRenderer {
}
@Override
protected Template getTemplate(final String templateDirName, final String templateName)
throws IOException {
protected Template getTemplate(final String templateDirName, final String templateName) {
try {
return TEMPLATE_CFG.getTemplate(templateName);
} catch (final IOException e) {
return null;
}
}
@Override
......
......@@ -101,12 +101,10 @@ public class StatisticMgmtService {
*
* @param request the specified request
* @param response the specified response
* @throws RepositoryException repository exception
* @throws JSONException json exception
* @throws ServiceException service exception
* @see Requests#searchEngineBotRequest(javax.servlet.http.HttpServletRequest)
*/
public void incBlogViewCount(final HttpServletRequest request, final HttpServletResponse response)
throws RepositoryException, JSONException {
public void incBlogViewCount(final HttpServletRequest request, final HttpServletResponse response) throws ServiceException {
if (Requests.searchEngineBotRequest(request)) {
return;
}
......@@ -115,22 +113,22 @@ public class StatisticMgmtService {
return;
}
final JSONObject statistic = statisticRepository.get(Statistic.STATISTIC);
final Transaction transaction = statisticRepository.beginTransaction();
JSONObject statistic = null;
try {
statistic = statisticRepository.get(Statistic.STATISTIC);
if (null == statistic) {
return;
}
LOGGER.log(Level.TRACE, "Before inc blog view count[statistic={0}]", statistic);
int blogViewCnt = statistic.getInt(Statistic.STATISTIC_BLOG_VIEW_COUNT);
int blogViewCnt = statistic.optInt(Statistic.STATISTIC_BLOG_VIEW_COUNT);
++blogViewCnt;
statistic.put(Statistic.STATISTIC_BLOG_VIEW_COUNT, blogViewCnt);
final Transaction transaction = statisticRepository.beginTransaction();
try {
statisticRepository.update(Statistic.STATISTIC, statistic);
transaction.commit();
......@@ -140,9 +138,11 @@ public class StatisticMgmtService {
}
LOGGER.log(Level.ERROR, "Updates blog view count failed", e);
return;
}
LOGGER.log(Level.DEBUG, "Inced blog view count[statistic={0}]", statistic);
LOGGER.log(Level.TRACE, "Inced blog view count[statistic={0}]", statistic);
}
/**
......
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