diff --git a/common/pages.go b/common/pages.go index f58b9bf5..87a0fc72 100644 --- a/common/pages.go +++ b/common/pages.go @@ -282,25 +282,25 @@ type ResetPage struct { /* WIP for dyntmpl */ type Panel struct { *BasePanelPage - HTMLID string + HTMLID string ClassNames string - TmplName string - Inner nobreak + TmplName string + Inner nobreak } type PanelAnalytics struct { *BasePanelPage FormAction string - TmplName string - Inner nobreak + TmplName string + Inner nobreak } -type PanelAnalyticsStd struct{ +type PanelAnalyticsStd struct { Graph PanelTimeGraph ViewItems []PanelAnalyticsItem TimeRange string Unit string TimeType string } -type PanelAnalyticsStdUnit struct{ +type PanelAnalyticsStdUnit struct { Graph PanelTimeGraph ViewItems []PanelAnalyticsItemUnit TimeRange string @@ -334,7 +334,7 @@ type PanelPage struct { type GridElement struct { ID string - Href string + Href string Body string Order int // For future use Class string @@ -387,7 +387,7 @@ type PanelAnalyticsItem struct { type PanelAnalyticsItemUnit struct { Time int64 Count int64 - Unit string + Unit string } type PanelAnalyticsPage struct { @@ -591,6 +591,10 @@ type PanelDebugPage struct { Goroutines int CPUs int MemStats runtime.MemStats + + TCache int + UCache int + TopicListThaw bool } type PageSimple struct { diff --git a/common/phrases/phrases.go b/common/phrases/phrases.go index e5625aba..c03a2b3b 100644 --- a/common/phrases/phrases.go +++ b/common/phrases/phrases.go @@ -99,6 +99,23 @@ func InitPhrases(lang string) error { // [prefix][name]phrase langPack.TmplPhrasesPrefixes = make(map[string]map[string]string) + var conMap = make(map[string]string) // Cache phrase strings so we can de-dupe items to reduce memory use. There appear to be some minor improvements with this, although we would need a more thorough check to be sure. + for name, phrase := range langPack.TmplPhrases { + _, ok := conMap[phrase] + if !ok { + conMap[phrase] = phrase + } + cItem := conMap[phrase] + prefix := strings.Split(name, ".")[0] + _, ok = langPack.TmplPhrasesPrefixes[prefix] + if !ok { + langPack.TmplPhrasesPrefixes[prefix] = make(map[string]string) + } + langPack.TmplPhrasesPrefixes[prefix][name] = cItem + } + + // [prefix][name]phrase + /*langPack.TmplPhrasesPrefixes = make(map[string]map[string]string) for name, phrase := range langPack.TmplPhrases { prefix := strings.Split(name, ".")[0] _, ok := langPack.TmplPhrasesPrefixes[prefix] @@ -106,7 +123,7 @@ func InitPhrases(lang string) error { langPack.TmplPhrasesPrefixes[prefix] = make(map[string]string) } langPack.TmplPhrasesPrefixes[prefix][name] = phrase - } + }*/ langPack.TmplIndicesToPhrases = make([][][]byte, len(langTmplIndicesToNames)) for tmplID, phraseNames := range langTmplIndicesToNames { diff --git a/common/template_init.go b/common/template_init.go index 5c909ca0..7dbc846b 100644 --- a/common/template_init.go +++ b/common/template_init.go @@ -1,6 +1,7 @@ package common import ( + "fmt" "html/template" "io" "log" @@ -301,7 +302,7 @@ func compileTemplates(wg *sync.WaitGroup, c *tmpl.CTemplateSet, themeName string tmpls.AddStd("account", "common.Account", accountPage) basePage := &BasePanelPage{header, PanelStats{}, "dashboard", ReportForumID} - tmpls.AddStd("panel", "common.Panel", Panel{basePage, "panel_dashboard_right","","panel_dashboard", inter}) + tmpls.AddStd("panel", "common.Panel", Panel{basePage, "panel_dashboard_right", "", "panel_dashboard", inter}) //tmpls.AddStd("panel_analytics", "common.PanelAnalytics", Panel{basePage, "panel_dashboard_right","panel_dashboard", inter}) var writeTemplate = func(name string, content interface{}) { @@ -688,6 +689,22 @@ func initDefaultTmplFuncMap() { return template.HTML(phrases.GetLevelPhrase(level)) } + fmap["bunit"] = func(byteInt interface{}) interface{} { + var byteFloat float64 + var unit string + switch bytes := byteInt.(type) { + case int: + byteFloat, unit = ConvertByteUnit(float64(bytes)) + case int64: + byteFloat, unit = ConvertByteUnit(float64(bytes)) + case uint64: + byteFloat, unit = ConvertByteUnit(float64(bytes)) + default: + panic("bytes is not an int, int64 or uint64") + } + return fmt.Sprintf("%.1f", byteFloat) + unit + } + fmap["abstime"] = func(timeInt interface{}) interface{} { time, ok := timeInt.(time.Time) if !ok { diff --git a/common/templates/templates.go b/common/templates/templates.go index 0602e650..1e6bf87e 100644 --- a/common/templates/templates.go +++ b/common/templates/templates.go @@ -74,7 +74,7 @@ type CTemplateSet struct { logger *log.Logger loggerf *os.File - lang string + lang string } func NewCTemplateSet(in string) *CTemplateSet { @@ -108,6 +108,7 @@ func NewCTemplateSet(in string) *CTemplateSet { "lang": true, //"langf":true, "level": true, + "bunit": true, "abstime": true, "reltime": true, "scope": true, @@ -117,7 +118,7 @@ func NewCTemplateSet(in string) *CTemplateSet { }, logger: log.New(f, "", log.LstdFlags), loggerf: f, - lang:in, + lang: in, } } @@ -443,13 +444,13 @@ func (c *CTemplateSet) compile(name string, content string, expects string, expe } if c.lang == "normal" { - fout += "// nolint\nfunc Template_" + fname + "(tmpl_" + fname + "_i interface{}, w io.Writer) error {\n" - fout += `tmpl_` + fname + `_vars, ok := tmpl_` + fname + `_i.(` + expects + `) + fout += "// nolint\nfunc Template_" + fname + "(tmpl_" + fname + "_i interface{}, w io.Writer) error {\n" + fout += `tmpl_` + fname + `_vars, ok := tmpl_` + fname + `_i.(` + expects + `) if !ok { return errors.New("invalid page struct value") } ` - fout += `var iw http.ResponseWriter + fout += `var iw http.ResponseWriter gzw, ok := w.(common.GzipResponseWriter) if ok { iw = gzw.ResponseWriter @@ -1116,6 +1117,17 @@ ArgLoop: litString("phrases.GetLevelPhrase("+leftParam+")", false) c.importMap[langPkg] = langPkg break ArgLoop + case "bunit": + // TODO: Implement bunit literals + leftOperand := node.Args[pos+1].String() + if len(leftOperand) == 0 { + panic("The leftoperand for function buint cannot be left blank") + } + leftParam, _ := c.compileIfVarSub(con, leftOperand) + out = "{\nbyteFloat, unit := common.ConvertByteUnit(float64(" + leftParam + "))\n" + out += "w.Write(fmt.Sprintf(\"%.1f\", byteFloat) + unit)\n" + literal = true + break ArgLoop case "abstime": // TODO: Implement level literals leftOperand := node.Args[pos+1].String() @@ -1407,7 +1419,7 @@ func (c *CTemplateSet) retCall(name string, params ...interface{}) { c.detail("returned from " + name + " => (" + pstr + ")") } -func buildUserExprs(holder string) ([]string,[]string) { +func buildUserExprs(holder string) ([]string, []string) { var userExprs = []string{ holder + ".CurrentUser.Loggedin", holder + ".CurrentUser.IsSuperMod", @@ -1825,4 +1837,4 @@ func (c *CTemplateSet) error(args ...interface{}) { func (c *CTemplateSet) critical(args ...interface{}) { c.logger.Println(args...) -} \ No newline at end of file +} diff --git a/common/topic_cache.go b/common/topic_cache.go index 40aadcdd..1549a732 100644 --- a/common/topic_cache.go +++ b/common/topic_cache.go @@ -125,37 +125,37 @@ func (mts *MemoryTopicCache) Remove(id int) error { } // RemoveUnsafe is the unsafe version of Remove. THIS METHOD IS NOT THREAD-SAFE. -func (mts *MemoryTopicCache) RemoveUnsafe(id int) error { - _, ok := mts.items[id] +func (s *MemoryTopicCache) RemoveUnsafe(id int) error { + _, ok := s.items[id] if !ok { return ErrNoRows } - delete(mts.items, id) - atomic.AddInt64(&mts.length, -1) + delete(s.items, id) + atomic.AddInt64(&s.length, -1) return nil } // Flush removes all the topics from the cache, useful for tests. -func (mts *MemoryTopicCache) Flush() { - mts.Lock() - mts.items = make(map[int]*Topic) - mts.length = 0 - mts.Unlock() +func (s *MemoryTopicCache) Flush() { + s.Lock() + s.items = make(map[int]*Topic) + s.length = 0 + s.Unlock() } // ! Is this concurrent? // Length returns the number of topics in the memory cache -func (mts *MemoryTopicCache) Length() int { - return int(mts.length) +func (s *MemoryTopicCache) Length() int { + return int(s.length) } // SetCapacity sets the maximum number of topics which this cache can hold -func (mts *MemoryTopicCache) SetCapacity(capacity int) { +func (s *MemoryTopicCache) SetCapacity(capacity int) { // Ints are moved in a single instruction, so this should be thread-safe - mts.capacity = capacity + s.capacity = capacity } // GetCapacity returns the maximum number of topics this cache can hold -func (mts *MemoryTopicCache) GetCapacity() int { - return mts.capacity +func (s *MemoryTopicCache) GetCapacity() int { + return s.capacity } diff --git a/langs/english.json b/langs/english.json index eaf999ec..3e48ea91 100644 --- a/langs/english.json +++ b/langs/english.json @@ -589,7 +589,7 @@ "forums_no_forums":"You don't have access to any forums.", "topic.opening_post_aria":"The opening post for this topic", - "topic.status_closed_aria":"This topic has been locked", + "topic.status_closed_aria":"This topic is locked", "topic.title_input_aria":"Topic Title Input", "topic.update_button":"Update", "topic.userinfo_aria":"The information on the poster", diff --git a/routes/panel/debug.go b/routes/panel/debug.go index fa112320..d21e4b28 100644 --- a/routes/panel/debug.go +++ b/routes/panel/debug.go @@ -41,6 +41,17 @@ func Debug(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError { var memStats runtime.MemStats runtime.ReadMemStats(&memStats) - pi := c.PanelDebugPage{basePage, goVersion, dbVersion, uptime, openConnCount, qgen.Builder.GetAdapter().GetName(), goroutines, cpus, memStats} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage,"panel_dashboard_right","","panel_debug", pi}) + var tlen, ulen int + tcache := c.Topics.GetCache() + if tcache != nil { + tlen = tcache.Length() + } + ucache := c.Users.GetCache() + if ucache != nil { + ulen = ucache.Length() + } + topicListThawed := c.TopicListThaw.Thawed() + + pi := c.PanelDebugPage{basePage, goVersion, dbVersion, uptime, openConnCount, qgen.Builder.GetAdapter().GetName(), goroutines, cpus, memStats, tlen, ulen, topicListThawed} + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_dashboard_right", "debug_page", "panel_debug", pi}) } diff --git a/templates/panel_debug.html b/templates/panel_debug.html index e40994d8..41b006db 100644 --- a/templates/panel_debug.html +++ b/templates/panel_debug.html @@ -9,7 +9,7 @@