Browse Source

feat:506优化

wangshan 1 year ago
parent
commit
01e94b6f94

+ 19 - 10
src/jfw/front/shorturl.go

@@ -44,6 +44,7 @@ type Short struct {
 	replication    xweb.Mapper `xweb:"/front/shorturl/replication"` //用户复制操作记录入库
 	nologinArticle xweb.Mapper `xweb:"/nologin/(\\w+)/(.*).html"`   //([pm]) 无需登录
 	whiteList      xweb.Mapper `xweb:"/initialize/whiteList"`       //白名单初始化
+	clearCache     xweb.Mapper `xweb:"/front/free/clearCache"`      //清楚缓存
 }
 
 var (
@@ -92,8 +93,17 @@ var (
 		"indexcontent":    true, //老首页 seo入口 供爬虫使用
 		"advancedProject": false,
 	}
+	cacheIndex = []byte{}
 )
 
+func (s *Short) ClearCache() {
+	log.Println("before cacheIndex:", string(cacheIndex))
+	if len(cacheIndex) > 0 {
+		cacheIndex = []byte{}
+	}
+	log.Println("after cacheIndex:", string(cacheIndex))
+}
+
 func (s *Short) WhiteList() error {
 	ipInitAuthentication := s.GetString("ipInitAuthentication")
 	if ipInitAuthentication == config.Sysconfig["ipInitAuthentication"] {
@@ -171,7 +181,7 @@ func (s *Short) LoginCommon(sess map[string]interface{}, stype, id string, bm bo
 			return s.Render("/pc/detail/biddetail_login.html", &s.T)
 		}
 	} else if userId != "" && strings.Contains(s.Request.RequestURI, "article") {
-		mobileHtmlKey := "jy_mobile_index_wx"
+		//mobileHtmlKey := "jy_mobile_index_wx"
 		var loginPageInfo = func() (body []byte) {
 			// 获取页面内容
 			mobileUrl := fmt.Sprintf("%s%s", config.Sysconfig["webdomain"].(string), "/jy_mobile/index.html")
@@ -196,20 +206,19 @@ func (s *Short) LoginCommon(sess map[string]interface{}, stype, id string, bm bo
 				log.Println(s.ResponseWriter, "Failed to read response body", http.StatusInternalServerError)
 				return
 			}
-			err = redis.PutBytes(redisLimitation, mobileHtmlKey, &body, 3*24*60*60)
-			if err != nil {
-				log.Println("mobile html redis cache err :", err.Error())
-			}
+			//err = redis.PutBytes(redisLimitation, mobileHtmlKey, &body, 3*24*60*60)
+			//if err != nil {
+			//	log.Println("mobile html redis cache err :", err.Error())
+			//}
 			return
 		}
 		// 将页面内容返回给前端
 		s.ResponseWriter.Header().Set("Content-Type", "text/html; charset=utf-8")
-		body, err := redis.GetBytes(redisLimitation, mobileHtmlKey)
-		if err == nil && body != nil && len(*body) > 0 {
-			s.ResponseWriter.Write(*body)
-			return nil
+		//body, err := redis.GetBytes(redisLimitation, mobileHtmlKey)
+		if len(cacheIndex) == 0 {
+			cacheIndex = loginPageInfo()
 		}
-		s.ResponseWriter.Write(loginPageInfo())
+		s.ResponseWriter.Write(cacheIndex)
 		return nil
 	}
 	//getsession := s.Session().GetMultiple()

+ 22 - 11
src/jfw/modules/app/src/app/front/shorturl.go

@@ -37,6 +37,7 @@ type Short struct {
 	replication  xweb.Mapper `xweb:"/jyapp/shorturl/replication"`               //用户复制操作记录入库
 	whiteList    xweb.Mapper `xweb:"/jyapp/initialize/whiteList"`               //白名单初始化
 	transitRoute xweb.Mapper `xweb:"/jyapp/transit/(.*)"`                       //中转路由
+	clearCache   xweb.Mapper `xweb:"/jyapp/free/clearCache"`                    //清楚缓存
 }
 
 func init() {
@@ -71,7 +72,18 @@ var TypeCodeMap = map[string]string{
 	"验收":   "验收公告信息",
 	"违规":   "违规信息",
 }
-var redisLimitation = "limitation"
+var (
+	redisLimitation = "limitation"
+	cacheIndex      = []byte{}
+)
+
+func (s *Short) ClearCache() {
+	log.Println("before cacheIndex:", string(cacheIndex))
+	if len(cacheIndex) > 0 {
+		cacheIndex = []byte{}
+	}
+	log.Println("after cacheIndex:", string(cacheIndex))
+}
 
 func (s *Short) WhiteList() error {
 	ipInitAuthentication := s.GetString("ipInitAuthentication")
@@ -99,7 +111,7 @@ func (s *Short) Article(contentType, stype, id string) error {
 	//userId = "637dcf3ff143ed326e9e1589"
 	//登录用户 权限
 	if userId != "" {
-		mobileHtmlKey := "jy_mobile_index_app"
+		//mobileHtmlKey := "jy_mobile_index_app"
 		var loginPageInfo = func() (body []byte) {
 			// 获取页面内容
 			mobileUrl := fmt.Sprintf("%s%s", config.Sysconfig["webdomain"].(string), "/jy_mobile/index.html")
@@ -123,20 +135,19 @@ func (s *Short) Article(contentType, stype, id string) error {
 				log.Println(s.ResponseWriter, "Failed to read response body", http.StatusInternalServerError)
 				return
 			}
-			err = redis.PutBytes(redisLimitation, mobileHtmlKey, &body, 3*24*60*60)
-			if err != nil {
-				log.Println("mobile html redis cache err :", err.Error())
-			}
+			//err = redis.PutBytes(redisLimitation, mobileHtmlKey, &body, 3*24*60*60)
+			//if err != nil {
+			//	log.Println("mobile html redis cache err :", err.Error())
+			//}
 			return
 		}
 		// 将页面内容返回给前端
 		s.ResponseWriter.Header().Set("Content-Type", "text/html; charset=utf-8")
-		body, err := redis.GetBytes(redisLimitation, mobileHtmlKey)
-		if err == nil && body != nil && len(*body) > 0 {
-			s.ResponseWriter.Write(*body)
-			return nil
+		//body, err := redis.GetBytes(redisLimitation, mobileHtmlKey)
+		if len(cacheIndex) == 0 {
+			cacheIndex = loginPageInfo()
 		}
-		s.ResponseWriter.Write(loginPageInfo())
+		s.ResponseWriter.Write(cacheIndex)
 		return nil
 	}
 	s.T["isVip"] = isVip

+ 1 - 1
src/jfw/modules/app/src/web/templates/weixin/wxinfocontent.html

@@ -1166,7 +1166,7 @@
       $(this).wrap('<div class="scroll-tab-container" style="max-width: 100%;overflow-x: scroll;"></div>')
     })
   });
-    var canRead = false //免费用户当天查看是否查看三次公告
+    var canRead = {{.T.canRead}} //免费用户当天查看是否查看三次公告
     var	shareimgflag = true;
     var area = {{.T.obj.area}}
     var subtype = {{.T.obj.subtype}}

+ 1 - 1
src/jfw/modules/publicapply/src/detail/dao/advanced.go

@@ -213,7 +213,7 @@ func (a *Advanced) ProjectSchedule() (eSch *entity.Schedule) {
 	eSch = &entity.Schedule{}
 	var projectSchedule = func() {
 		projectInfos := elastic.Get("projectset", "projectset", `{"query": {"bool": {"must": [{"match": {"list.infoid": "`+a.Id+`"}}]}},"_source":["list","projectname"],"from": 0,"size": 1}`)
-		if len(*projectInfos) != 0 {
+		if projectInfos != nil && len(*projectInfos) > 0 {
 			projectInfo := (*projectInfos)[0]
 			eSch.ProjectName = common.InterfaceToStr(projectInfo["projectname"])
 			list, ok := projectInfo["list"].([]interface{})