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

#17

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