add Count() method to PollStore
show daily task count on debug page optimise count queries on debug page use Count() methods on debug page where ever possible
This commit is contained in:
parent
4670375933
commit
cff2e96915
@ -744,6 +744,7 @@ type DebugPageTasks struct {
|
||||
Second int
|
||||
FifteenMinute int
|
||||
Hour int
|
||||
Day int
|
||||
Shutdown int
|
||||
}
|
||||
|
||||
@ -813,13 +814,18 @@ type PanelDebugPage struct {
|
||||
Disk DebugPageDisk
|
||||
}
|
||||
|
||||
type PanelDebugTaskTask struct {
|
||||
type PanelTaskTask struct {
|
||||
Name string
|
||||
Type int // 0 = halfsec, 1 = sec, 2 = fifteenmin, 3 = hour, 4 = shutdown
|
||||
}
|
||||
type PanelDebugTaskPage struct {
|
||||
type PanelTaskType struct {
|
||||
Name string
|
||||
FAvg string
|
||||
}
|
||||
type PanelTaskPage struct {
|
||||
*BasePanelPage
|
||||
Tasks []PanelDebugTaskTask
|
||||
Tasks []PanelTaskTask
|
||||
Types []PanelTaskType
|
||||
}
|
||||
|
||||
type PageSimple struct {
|
||||
|
@ -29,7 +29,7 @@ type PollStore interface {
|
||||
ClearIPs() error
|
||||
Create(parent Pollable, pollType int, pollOptions map[int]string) (int, error)
|
||||
Reload(id int) error
|
||||
//Count() int
|
||||
Count() int
|
||||
|
||||
SetCache(cache PollCache)
|
||||
GetCache() PollCache
|
||||
@ -43,7 +43,7 @@ type DefaultPollStore struct {
|
||||
createPoll *sql.Stmt
|
||||
createPollOption *sql.Stmt
|
||||
delete *sql.Stmt
|
||||
//count *sql.Stmt
|
||||
count *sql.Stmt
|
||||
|
||||
clearIPs *sql.Stmt
|
||||
}
|
||||
@ -61,7 +61,7 @@ func NewDefaultPollStore(cache PollCache) (*DefaultPollStore, error) {
|
||||
exists: acc.Select(p).Columns("pollID").Where("pollID=?").Stmt(),
|
||||
createPoll: acc.Insert(p).Columns("parentID,parentTable,type,options").Fields("?,?,?,?").Prepare(),
|
||||
createPollOption: acc.Insert("polls_options").Columns("pollID,option,votes").Fields("?,?,0").Prepare(),
|
||||
//count: acc.SimpleCount(p, "", ""),
|
||||
count: acc.Count(p).Prepare(),
|
||||
|
||||
clearIPs: acc.Update("polls_votes").Set("ip=''").Where("ip!=''").Stmt(),
|
||||
}, acc.FirstError()
|
||||
@ -231,6 +231,10 @@ func (s *DefaultPollStore) Create(parent Pollable, pollType int, pollOptions map
|
||||
return id, parent.SetPoll(id) // TODO: Delete the poll (and options) if SetPoll fails
|
||||
}
|
||||
|
||||
func (s *DefaultPollStore) Count() int {
|
||||
return Count(s.count)
|
||||
}
|
||||
|
||||
func (s *DefaultPollStore) SetCache(cache PollCache) {
|
||||
s.cache = cache
|
||||
}
|
||||
|
@ -1500,6 +1500,7 @@ func TestPolls(t *testing.T) {
|
||||
shouldNotExist(-1)
|
||||
shouldNotExist(0)
|
||||
shouldNotExist(1)
|
||||
exf(c.Polls.Count() == 0, "count should be %d not %d", 0, c.Polls.Count())
|
||||
|
||||
tid, e := c.Topics.Create(2, "Poll Test", "Filler Body", 1, "")
|
||||
expectNilErr(t, e)
|
||||
@ -1513,6 +1514,7 @@ func TestPolls(t *testing.T) {
|
||||
expectNilErr(t, e)
|
||||
exf(pid == 1, "poll id should be 1 not %d", pid)
|
||||
ex(c.Polls.Exists(1), "poll 1 should exist")
|
||||
exf(c.Polls.Count() == 1, "count should be %d not %d", 1, c.Polls.Count())
|
||||
|
||||
testPoll := func(p *c.Poll, id, parentID int, parentTable string, ptype int, antiCheat bool, voteCount int) {
|
||||
ef := exf
|
||||
@ -1546,6 +1548,7 @@ func TestPolls(t *testing.T) {
|
||||
ex(!c.Polls.Exists(1), "poll 1 should no longer exist")
|
||||
_, e = c.Polls.Get(1)
|
||||
recordMustNotExist(t, e, "poll 1 should no longer exist")
|
||||
exf(c.Polls.Count() == 0, "count should be %d not %d", 0, c.Polls.Count())
|
||||
}
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
qgen "github.com/Azareal/Gosora/query_gen"
|
||||
)
|
||||
|
||||
func Debug(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
||||
basePage, ferr := buildBasePage(w, r, user, "debug", "debug")
|
||||
func Debug(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError {
|
||||
bp, ferr := buildBasePage(w, r, u, "debug", "debug")
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
@ -46,7 +46,7 @@ func Debug(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
||||
cpus := runtime.NumCPU()
|
||||
httpConns := c.ConnWatch.Count()
|
||||
|
||||
debugTasks := c.DebugPageTasks{c.Tasks.HalfSec.Count(), c.Tasks.Sec.Count(), c.Tasks.FifteenMin.Count(), c.Tasks.Hour.Count(), c.Tasks.Shutdown.Count()}
|
||||
debugTasks := c.DebugPageTasks{c.Tasks.HalfSec.Count(), c.Tasks.Sec.Count(), c.Tasks.FifteenMin.Count(), c.Tasks.Hour.Count(), c.Tasks.Day.Count(), c.Tasks.Shutdown.Count()}
|
||||
var memStats runtime.MemStats
|
||||
runtime.ReadMemStats(&memStats)
|
||||
|
||||
@ -69,11 +69,12 @@ func Debug(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
||||
debugCache := c.DebugPageCache{tlen, ulen, rlen, tcap, ucap, rcap, topicListThawed}
|
||||
|
||||
var fErr error
|
||||
acc := qgen.NewAcc()
|
||||
count := func(tbl string) int {
|
||||
if fErr != nil {
|
||||
return 0
|
||||
}
|
||||
c, err := qgen.NewAcc().Count(tbl).Total()
|
||||
c, err := acc.Count(tbl).Total()
|
||||
fErr = err
|
||||
return c
|
||||
}
|
||||
@ -81,12 +82,19 @@ func Debug(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
||||
// TODO: Call Count on an attachment store
|
||||
attachs := count("attachments")
|
||||
// TODO: Implement a PollStore and call Count on that instead
|
||||
polls := count("polls")
|
||||
//polls := count("polls")
|
||||
polls := c.Polls.Count()
|
||||
//pollsOptions := count("polls_options") // TODO: Add this
|
||||
//pollsVotes := count("polls_votes") // TODO: Add this
|
||||
|
||||
loginLogs := count("login_logs")
|
||||
regLogs := count("registration_logs")
|
||||
modLogs := count("moderation_logs")
|
||||
adminLogs := count("administration_logs")
|
||||
//loginLogs := count("login_logs")
|
||||
loginLogs := c.LoginLogs.Count()
|
||||
//regLogs := count("registration_logs")
|
||||
regLogs := c.RegLogs.Count()
|
||||
//modLogs := count("moderation_logs")
|
||||
modLogs := c.ModLogs.Count()
|
||||
//adminLogs := count("administration_logs")
|
||||
adminLogs := c.AdminLogs.Count()
|
||||
|
||||
views := count("viewchunks")
|
||||
viewsAgents := count("viewchunks_agents")
|
||||
@ -125,18 +133,19 @@ func Debug(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
||||
|
||||
debugDisk := c.DebugPageDisk{staticSize, attachSize, uploadsSize, logsSize, backupsSize, gitSize}
|
||||
|
||||
pi := c.PanelDebugPage{basePage, goVersion, dbVersion, uptime, openConnCount, qgen.Builder.GetAdapter().GetName(), goroutines, cpus, httpConns, debugTasks, memStats, debugCache, debugDatabase, debugDisk}
|
||||
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_dashboard_right", "debug_page", "panel_debug", pi})
|
||||
pi := c.PanelDebugPage{bp, goVersion, dbVersion, uptime, openConnCount, qgen.Builder.GetAdapter().GetName(), goroutines, cpus, httpConns, debugTasks, memStats, debugCache, debugDatabase, debugDisk}
|
||||
return renderTemplate("panel", w, r, bp.Header, c.Panel{bp, "panel_dashboard_right", "debug_page", "panel_debug", pi})
|
||||
}
|
||||
|
||||
func DebugTasks(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
||||
basePage, ferr := buildBasePage(w, r, user, "debug", "debug")
|
||||
func DebugTasks(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError {
|
||||
bp, ferr := buildBasePage(w, r, u, "debug", "debug")
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
|
||||
var debugTasks []c.PanelDebugTaskTask
|
||||
var tasks []c.PanelTaskTask
|
||||
var taskTypes []c.PanelTaskType
|
||||
|
||||
pi := c.PanelDebugTaskPage{basePage, debugTasks}
|
||||
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_dashboard_right", "debug_page", "panel_debug_task", pi})
|
||||
pi := c.PanelTaskPage{bp, tasks, taskTypes}
|
||||
return renderTemplate("panel", w, r, bp.Header, c.Panel{bp, "panel_dashboard_right", "debug_page", "panel_debug_task", pi})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user