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

修复浏览计数问题

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