save bytes in client templates

This commit is contained in:
Azareal 2020-03-22 10:25:10 +10:00
parent 5419af9c1c
commit 75ed0cd5f2
5 changed files with 23 additions and 19 deletions

View File

@ -185,13 +185,18 @@ func (list SFileList) JSTmplInit() error {
data = replace(data, " c.", "")
data = replace(data, "phrases.", "")
data = replace(data, ", 10;", "")
//data = replace(data, "var plist = GetTmplPhrasesBytes("+shortName+"_tmpl_phrase_id)", "const plist = tmplPhrases[\""+tmplName+"\"];")
data = replace(data, "//var plist = GetTmplPhrasesBytes("+shortName+"_tmpl_phrase_id)", "const "+shortName+"_phrase_arr = tmplPhrases[\""+tmplName+"\"];")
data = replace(data, "var cached_var_", "let cached_var_")
data = replace(data, `tmpl_vars, ok := tmpl_i.`, `/*`)
//data = replace(data, "//var plist = GetTmplPhrasesBytes("+shortName+"_tmpl_phrase_id)", "const "+shortName+"_phrase_arr = tmplPhrases[\""+tmplName+"\"];")
data = replace(data, "//var plist = GetTmplPhrasesBytes("+shortName+"_tmpl_phrase_id)", "const pl=tmplPhrases[\""+tmplName+"\"];")
data = replace(data, shortName+"_phrase_arr", "pl")
data = replace(data, "tmpl_"+shortName+"_vars", "t_vars")
data = replace(data, "var c_var_", "let c_var_")
data = replace(data, `t_vars, ok := tmpl_i.`, `/*`)
data = replace(data, "[]byte(", "")
data = replace(data, "StringToBytes(", "")
data = replace(data, "RelativeTime(tmpl_"+shortName+"_vars.", "tmpl_"+shortName+"_vars.Relative")
data = replace(data, "RelativeTime(t_vars.", "t_vars.Relative")
// TODO: Format dates properly on the client side
data = replace(data, ".Format(\"2006-01-02 15:04:05\"", "")
data = replace(data, ", 10", "")
@ -239,7 +244,7 @@ func (list SFileList) JSTmplInit() error {
return err
}
// Don't use Gzip if we get meagre gains from it as it takes longer to process the responses
if len(gzipData) >= (len(data) + 150) {
if len(gzipData) >= (len(data) + 120) {
gzipData = nil
} else {
diff := len(data) - len(gzipData)

View File

@ -1959,7 +1959,7 @@ func (c *CTemplateSet) afterTemplate(con CContext, startIndex int) {
varmap := make(map[string]int)
for name, count := range varcounts {
if count > 1 {
varstr += "var cached_var_" + strconv.Itoa(i) + " = " + name + "\n"
varstr += "var c_var_" + strconv.Itoa(i) + "=" + name + "\n"
varmap[name] = i
i++
}
@ -1979,7 +1979,7 @@ func (c *CTemplateSet) afterTemplate(con CContext, startIndex int) {
} else if item.Type == "varsub" && loopDepth == 0 {
index, ok := varmap[item.Body]
if ok {
item.Body = "cached_var_" + strconv.Itoa(index)
item.Body = "c_var_" + strconv.Itoa(index)
item.Type = "cvarsub"
outBuf[i] = item
}

View File

@ -26,8 +26,7 @@
<a class="moderate_link" href="#" aria-label="{{lang "topic_list.moderate_aria"}}"></a>
</div>
{{else}}<div class="opt locked_opt" title="{{lang "topics_locked_tooltip"}}" aria-label="{{lang "topics_locked_aria"}}"><a></a></div>{{end}}
</div>
<div style="clear:both;"></div>
</div><div style="clear:both;"></div>
{{end}}
</div>