Commit 4626a92b authored by Liang Ding's avatar Liang Ding

页面静态化 #107

parent cc540d0b
...@@ -15,7 +15,6 @@ import org.b3log.latke.Keys; ...@@ -15,7 +15,6 @@ import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Singleton; import org.b3log.latke.ioc.Singleton;
import org.b3log.solo.model.Article; import org.b3log.solo.model.Article;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -79,7 +78,6 @@ public class ArticleCache { ...@@ -79,7 +78,6 @@ public class ArticleCache {
public void putArticle(final JSONObject article) { public void putArticle(final JSONObject article) {
idCache.put(article.optString(Keys.OBJECT_ID), Solos.clone(article)); idCache.put(article.optString(Keys.OBJECT_ID), Solos.clone(article));
permalinkCache.put(article.optString(Article.ARTICLE_PERMALINK), Solos.clone(article)); permalinkCache.put(article.optString(Article.ARTICLE_PERMALINK), Solos.clone(article));
Statics.clear();
} }
/** /**
...@@ -95,7 +93,6 @@ public class ArticleCache { ...@@ -95,7 +93,6 @@ public class ArticleCache {
final String permalink = article.optString(Article.ARTICLE_PERMALINK); final String permalink = article.optString(Article.ARTICLE_PERMALINK);
idCache.remove(id); idCache.remove(id);
permalinkCache.remove(permalink); permalinkCache.remove(permalink);
Statics.clear();
} }
/** /**
...@@ -104,6 +101,5 @@ public class ArticleCache { ...@@ -104,6 +101,5 @@ public class ArticleCache {
public void clear() { public void clear() {
idCache.clear(); idCache.clear();
permalinkCache.clear(); permalinkCache.clear();
Statics.clear();
} }
} }
\ No newline at end of file
...@@ -14,7 +14,6 @@ package org.b3log.solo.cache; ...@@ -14,7 +14,6 @@ package org.b3log.solo.cache;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Singleton; import org.b3log.latke.ioc.Singleton;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -57,7 +56,6 @@ public class CommentCache { ...@@ -57,7 +56,6 @@ public class CommentCache {
*/ */
public void putComment(final JSONObject comment) { public void putComment(final JSONObject comment) {
cache.put(comment.optString(Keys.OBJECT_ID), Solos.clone(comment)); cache.put(comment.optString(Keys.OBJECT_ID), Solos.clone(comment));
Statics.clear();
} }
/** /**
...@@ -67,7 +65,6 @@ public class CommentCache { ...@@ -67,7 +65,6 @@ public class CommentCache {
*/ */
public void removeComment(final String id) { public void removeComment(final String id) {
cache.remove(id); cache.remove(id);
Statics.clear();
} }
/** /**
...@@ -75,6 +72,5 @@ public class CommentCache { ...@@ -75,6 +72,5 @@ public class CommentCache {
*/ */
public void clear() { public void clear() {
cache.clear(); cache.clear();
Statics.clear();
} }
} }
...@@ -15,7 +15,6 @@ import org.b3log.latke.Keys; ...@@ -15,7 +15,6 @@ import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Singleton; import org.b3log.latke.ioc.Singleton;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -73,7 +72,6 @@ public class OptionCache { ...@@ -73,7 +72,6 @@ public class OptionCache {
*/ */
public void putCategory(final String category, final JSONObject mergedOptions) { public void putCategory(final String category, final JSONObject mergedOptions) {
categoryCache.put(category, mergedOptions); categoryCache.put(category, mergedOptions);
Statics.clear();
} }
/** /**
...@@ -101,8 +99,6 @@ public class OptionCache { ...@@ -101,8 +99,6 @@ public class OptionCache {
final String category = option.optString(Option.OPTION_CATEGORY); final String category = option.optString(Option.OPTION_CATEGORY);
removeCategory(category); removeCategory(category);
Statics.clear();
} }
/** /**
...@@ -120,7 +116,6 @@ public class OptionCache { ...@@ -120,7 +116,6 @@ public class OptionCache {
removeCategory(category); removeCategory(category);
cache.remove(id); cache.remove(id);
Statics.clear();
} }
/** /**
...@@ -129,6 +124,5 @@ public class OptionCache { ...@@ -129,6 +124,5 @@ public class OptionCache {
public void clear() { public void clear() {
cache.clear(); cache.clear();
categoryCache.clear(); categoryCache.clear();
Statics.clear();
} }
} }
...@@ -14,7 +14,6 @@ package org.b3log.solo.cache; ...@@ -14,7 +14,6 @@ package org.b3log.solo.cache;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Singleton; import org.b3log.latke.ioc.Singleton;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -59,7 +58,6 @@ public class PageCache { ...@@ -59,7 +58,6 @@ public class PageCache {
final String pageId = page.optString(Keys.OBJECT_ID); final String pageId = page.optString(Keys.OBJECT_ID);
cache.put(pageId, Solos.clone(page)); cache.put(pageId, Solos.clone(page));
Statics.clear();
} }
/** /**
...@@ -69,7 +67,6 @@ public class PageCache { ...@@ -69,7 +67,6 @@ public class PageCache {
*/ */
public void removePage(final String id) { public void removePage(final String id) {
cache.remove(id); cache.remove(id);
Statics.clear();
} }
/** /**
...@@ -77,6 +74,5 @@ public class PageCache { ...@@ -77,6 +74,5 @@ public class PageCache {
*/ */
public void clear() { public void clear() {
cache.clear(); cache.clear();
Statics.clear();
} }
} }
...@@ -29,6 +29,7 @@ import org.b3log.latke.util.Requests; ...@@ -29,6 +29,7 @@ import org.b3log.latke.util.Requests;
import org.b3log.solo.model.UserExt; import org.b3log.solo.model.UserExt;
import org.b3log.solo.service.*; import org.b3log.solo.service.*;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Map; import java.util.Map;
...@@ -42,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -42,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
* </ul> * </ul>
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.0.0, Feb 9, 2020 * @version 2.0.0.1, Apr 14, 2020
* @since 2.9.5 * @since 2.9.5
*/ */
@Singleton @Singleton
...@@ -195,6 +196,7 @@ public class OAuthProcessor { ...@@ -195,6 +196,7 @@ public class OAuthProcessor {
} }
Solos.login(user, response); Solos.login(user, response);
Statics.clear();
context.sendRedirect(referer); context.sendRedirect(referer);
LOGGER.log(Level.INFO, "Logged in [name={}, remoteAddr={}] with oauth", userName, Requests.getRemoteAddr(request)); LOGGER.log(Level.INFO, "Logged in [name={}, remoteAddr={}] with oauth", userName, Requests.getRemoteAddr(request));
} }
......
...@@ -32,6 +32,7 @@ import org.b3log.solo.event.EventTypes; ...@@ -32,6 +32,7 @@ import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.*; import org.b3log.solo.model.*;
import org.b3log.solo.repository.*; import org.b3log.solo.repository.*;
import org.b3log.solo.util.GitHubs; import org.b3log.solo.util.GitHubs;
import org.b3log.solo.util.Statics;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -471,6 +472,8 @@ public class ArticleMgmtService { ...@@ -471,6 +472,8 @@ public class ArticleMgmtService {
} }
transaction.commit(); transaction.commit();
Statics.clear();
} catch (final ServiceException e) { } catch (final ServiceException e) {
if (transaction.isActive()) { if (transaction.isActive()) {
transaction.rollback(); transaction.rollback();
...@@ -565,6 +568,8 @@ public class ArticleMgmtService { ...@@ -565,6 +568,8 @@ public class ArticleMgmtService {
articleRepository.add(article); articleRepository.add(article);
transaction.commit(); transaction.commit();
Statics.clear();
article.put(Common.POST_TO_COMMUNITY, postToCommunity); article.put(Common.POST_TO_COMMUNITY, postToCommunity);
if (Article.ARTICLE_STATUS_C_PUBLISHED == article.optInt(ARTICLE_STATUS)) { if (Article.ARTICLE_STATUS_C_PUBLISHED == article.optInt(ARTICLE_STATUS)) {
final JSONObject eventData = new JSONObject(); final JSONObject eventData = new JSONObject();
...@@ -596,6 +601,8 @@ public class ArticleMgmtService { ...@@ -596,6 +601,8 @@ public class ArticleMgmtService {
articleRepository.remove(articleId); articleRepository.remove(articleId);
commentRepository.removeComments(articleId); commentRepository.removeComments(articleId);
transaction.commit(); transaction.commit();
Statics.clear();
} catch (final Exception e) { } catch (final Exception e) {
if (transaction.isActive()) { if (transaction.isActive()) {
transaction.rollback(); transaction.rollback();
......
...@@ -75,6 +75,11 @@ public final class Statics { ...@@ -75,6 +75,11 @@ public final class Statics {
* @return HTML, returns {@code null} if not found * @return HTML, returns {@code null} if not found
*/ */
public static String get(final RequestContext context) { public static String get(final RequestContext context) {
if (Solos.isLoggedIn(context)) {
// 登录用户不走缓存
return null;
}
final String key = key(context); final String key = key(context);
if (null == key) { if (null == key) {
return null; return null;
...@@ -101,6 +106,11 @@ public final class Statics { ...@@ -101,6 +106,11 @@ public final class Statics {
* @param context the specified context * @param context the specified context
*/ */
public static void put(final RequestContext context) { public static void put(final RequestContext context) {
if (Solos.isLoggedIn(context)) {
// 登录用户生成的内容不写入缓存
return;
}
final String key = key(context); final String key = key(context);
if (null == key) { if (null == key) {
return; return;
......
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