Commit 010b039d authored by Liang Ding's avatar Liang Ding

#17

parent 6f395e3e
...@@ -52,7 +52,7 @@ import static org.b3log.solo.model.Article.*; ...@@ -52,7 +52,7 @@ import static org.b3log.solo.model.Article.*;
* Article management service. * Article management service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.4.0, Nov 7, 2019 * @version 1.3.4.1, Jan 8, 2020
* @since 0.3.5 * @since 0.3.5
*/ */
@Service @Service
...@@ -649,36 +649,35 @@ public class ArticleMgmtService { ...@@ -649,36 +649,35 @@ public class ArticleMgmtService {
* @throws ServiceException service exception * @throws ServiceException service exception
*/ */
public void incViewCount(final String articleId) throws ServiceException { public void incViewCount(final String articleId) throws ServiceException {
JSONObject article; // JSONObject article;
//
try { // try {
article = articleRepository.get(articleId); // article = articleRepository.get(articleId);
//
if (null == article) { // if (null == article) {
return; // return;
} // }
} catch (final RepositoryException e) { // } catch (final RepositoryException e) {
LOGGER.log(Level.ERROR, "Gets article [id=" + articleId + "] failed", e); // LOGGER.log(Level.ERROR, "Gets article [id=" + articleId + "] failed", e);
//
return; // return;
} // }
//
final Transaction transaction = articleRepository.beginTransaction(); // final Transaction transaction = articleRepository.beginTransaction();
// try {
try { // article.put(Article.ARTICLE_VIEW_COUNT, article.getInt(Article.ARTICLE_VIEW_COUNT) + 1);
article.put(Article.ARTICLE_VIEW_COUNT, article.getInt(Article.ARTICLE_VIEW_COUNT) + 1); // articleRepository.update(articleId, article, ARTICLE_VIEW_COUNT);
articleRepository.update(articleId, article, ARTICLE_VIEW_COUNT); //
// transaction.commit();
transaction.commit(); // } catch (final Exception e) {
} catch (final Exception e) { // if (transaction.isActive()) {
if (transaction.isActive()) { // transaction.rollback();
transaction.rollback(); // }
} //
// LOGGER.log(Level.WARN, "Updates article view count failed");
LOGGER.log(Level.WARN, "Updates article view count failed"); //
// throw new ServiceException(e);
throw new ServiceException(e); // }
}
} }
/** /**
......
...@@ -48,7 +48,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -48,7 +48,7 @@ import java.util.concurrent.ConcurrentHashMap;
* Statistic management service. * Statistic management service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.1.4, Nov 19, 2019 * @version 2.0.1.5, Jan 8, 2020
* @since 0.5.0 * @since 0.5.0
*/ */
@Service @Service
...@@ -211,40 +211,40 @@ public class StatisticMgmtService { ...@@ -211,40 +211,40 @@ public class StatisticMgmtService {
* @throws ServiceException service exception * @throws ServiceException service exception
*/ */
public void incBlogViewCount(final RequestContext context, final Response response) throws ServiceException { public void incBlogViewCount(final RequestContext context, final Response response) throws ServiceException {
if (Solos.isBot(context.getRequest())) { // if (Solos.isBot(context.getRequest())) {
return; // return;
} // }
//
if (hasBeenServed(context, response)) { // if (hasBeenServed(context, response)) {
return; // return;
} // }
//
final Transaction transaction = optionRepository.beginTransaction(); // final Transaction transaction = optionRepository.beginTransaction();
JSONObject statistic; // JSONObject statistic;
try { // try {
statistic = optionRepository.get(Option.ID_C_STATISTIC_BLOG_VIEW_COUNT); // statistic = optionRepository.get(Option.ID_C_STATISTIC_BLOG_VIEW_COUNT);
if (null == statistic) { // if (null == statistic) {
return; // return;
} // }
//
LOGGER.log(Level.TRACE, "Before inc blog view count is [{0}]", statistic); // LOGGER.log(Level.TRACE, "Before inc blog view count is [{0}]", statistic);
//
statistic.put(Option.OPTION_VALUE, statistic.optInt(Option.OPTION_VALUE) + 1); // statistic.put(Option.OPTION_VALUE, statistic.optInt(Option.OPTION_VALUE) + 1);
//
updateStatistic(Option.ID_C_STATISTIC_BLOG_VIEW_COUNT, statistic); // updateStatistic(Option.ID_C_STATISTIC_BLOG_VIEW_COUNT, statistic);
//
transaction.commit(); // transaction.commit();
} catch (final RepositoryException e) { // } catch (final RepositoryException e) {
if (transaction.isActive()) { // if (transaction.isActive()) {
transaction.rollback(); // transaction.rollback();
} // }
//
LOGGER.log(Level.ERROR, "Updates blog view count failed", e); // LOGGER.log(Level.ERROR, "Updates blog view count failed", e);
//
return; // return;
} // }
//
LOGGER.log(Level.TRACE, "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