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
|
Second int
|
||||||
FifteenMinute int
|
FifteenMinute int
|
||||||
Hour int
|
Hour int
|
||||||
|
Day int
|
||||||
Shutdown int
|
Shutdown int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -813,13 +814,18 @@ type PanelDebugPage struct {
|
||||||
Disk DebugPageDisk
|
Disk DebugPageDisk
|
||||||
}
|
}
|
||||||
|
|
||||||
type PanelDebugTaskTask struct {
|
type PanelTaskTask struct {
|
||||||
Name string
|
Name string
|
||||||
Type int // 0 = halfsec, 1 = sec, 2 = fifteenmin, 3 = hour, 4 = shutdown
|
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
|
*BasePanelPage
|
||||||
Tasks []PanelDebugTaskTask
|
Tasks []PanelTaskTask
|
||||||
|
Types []PanelTaskType
|
||||||
}
|
}
|
||||||
|
|
||||||
type PageSimple struct {
|
type PageSimple struct {
|
||||||
|
|
|
@ -29,7 +29,7 @@ type PollStore interface {
|
||||||
ClearIPs() error
|
ClearIPs() error
|
||||||
Create(parent Pollable, pollType int, pollOptions map[int]string) (int, error)
|
Create(parent Pollable, pollType int, pollOptions map[int]string) (int, error)
|
||||||
Reload(id int) error
|
Reload(id int) error
|
||||||
//Count() int
|
Count() int
|
||||||
|
|
||||||
SetCache(cache PollCache)
|
SetCache(cache PollCache)
|
||||||
GetCache() PollCache
|
GetCache() PollCache
|
||||||
|
@ -43,7 +43,7 @@ type DefaultPollStore struct {
|
||||||
createPoll *sql.Stmt
|
createPoll *sql.Stmt
|
||||||
createPollOption *sql.Stmt
|
createPollOption *sql.Stmt
|
||||||
delete *sql.Stmt
|
delete *sql.Stmt
|
||||||
//count *sql.Stmt
|
count *sql.Stmt
|
||||||
|
|
||||||
clearIPs *sql.Stmt
|
clearIPs *sql.Stmt
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ func NewDefaultPollStore(cache PollCache) (*DefaultPollStore, error) {
|
||||||
exists: acc.Select(p).Columns("pollID").Where("pollID=?").Stmt(),
|
exists: acc.Select(p).Columns("pollID").Where("pollID=?").Stmt(),
|
||||||
createPoll: acc.Insert(p).Columns("parentID,parentTable,type,options").Fields("?,?,?,?").Prepare(),
|
createPoll: acc.Insert(p).Columns("parentID,parentTable,type,options").Fields("?,?,?,?").Prepare(),
|
||||||
createPollOption: acc.Insert("polls_options").Columns("pollID,option,votes").Fields("?,?,0").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(),
|
clearIPs: acc.Update("polls_votes").Set("ip=''").Where("ip!=''").Stmt(),
|
||||||
}, acc.FirstError()
|
}, 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
|
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) {
|
func (s *DefaultPollStore) SetCache(cache PollCache) {
|
||||||
s.cache = cache
|
s.cache = cache
|
||||||
}
|
}
|
||||||
|
|
|
@ -1500,6 +1500,7 @@ func TestPolls(t *testing.T) {
|
||||||
shouldNotExist(-1)
|
shouldNotExist(-1)
|
||||||
shouldNotExist(0)
|
shouldNotExist(0)
|
||||||
shouldNotExist(1)
|
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, "")
|
tid, e := c.Topics.Create(2, "Poll Test", "Filler Body", 1, "")
|
||||||
expectNilErr(t, e)
|
expectNilErr(t, e)
|
||||||
|
@ -1513,6 +1514,7 @@ func TestPolls(t *testing.T) {
|
||||||
expectNilErr(t, e)
|
expectNilErr(t, e)
|
||||||
exf(pid == 1, "poll id should be 1 not %d", pid)
|
exf(pid == 1, "poll id should be 1 not %d", pid)
|
||||||
ex(c.Polls.Exists(1), "poll 1 should exist")
|
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) {
|
testPoll := func(p *c.Poll, id, parentID int, parentTable string, ptype int, antiCheat bool, voteCount int) {
|
||||||
ef := exf
|
ef := exf
|
||||||
|
@ -1546,6 +1548,7 @@ func TestPolls(t *testing.T) {
|
||||||
ex(!c.Polls.Exists(1), "poll 1 should no longer exist")
|
ex(!c.Polls.Exists(1), "poll 1 should no longer exist")
|
||||||
_, e = c.Polls.Get(1)
|
_, e = c.Polls.Get(1)
|
||||||
recordMustNotExist(t, e, "poll 1 should no longer exist")
|
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) {
|
func TestSearch(t *testing.T) {
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
qgen "github.com/Azareal/Gosora/query_gen"
|
qgen "github.com/Azareal/Gosora/query_gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Debug(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
func Debug(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError {
|
||||||
basePage, ferr := buildBasePage(w, r, user, "debug", "debug")
|
bp, ferr := buildBasePage(w, r, u, "debug", "debug")
|
||||||
if ferr != nil {
|
if ferr != nil {
|
||||||
return ferr
|
return ferr
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func Debug(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
||||||
cpus := runtime.NumCPU()
|
cpus := runtime.NumCPU()
|
||||||
httpConns := c.ConnWatch.Count()
|
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
|
var memStats runtime.MemStats
|
||||||
runtime.ReadMemStats(&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}
|
debugCache := c.DebugPageCache{tlen, ulen, rlen, tcap, ucap, rcap, topicListThawed}
|
||||||
|
|
||||||
var fErr error
|
var fErr error
|
||||||
|
acc := qgen.NewAcc()
|
||||||
count := func(tbl string) int {
|
count := func(tbl string) int {
|
||||||
if fErr != nil {
|
if fErr != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
c, err := qgen.NewAcc().Count(tbl).Total()
|
c, err := acc.Count(tbl).Total()
|
||||||
fErr = err
|
fErr = err
|
||||||
return c
|
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
|
// TODO: Call Count on an attachment store
|
||||||
attachs := count("attachments")
|
attachs := count("attachments")
|
||||||
// TODO: Implement a PollStore and call Count on that instead
|
// 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")
|
//loginLogs := count("login_logs")
|
||||||
regLogs := count("registration_logs")
|
loginLogs := c.LoginLogs.Count()
|
||||||
modLogs := count("moderation_logs")
|
//regLogs := count("registration_logs")
|
||||||
adminLogs := count("administration_logs")
|
regLogs := c.RegLogs.Count()
|
||||||
|
//modLogs := count("moderation_logs")
|
||||||
|
modLogs := c.ModLogs.Count()
|
||||||
|
//adminLogs := count("administration_logs")
|
||||||
|
adminLogs := c.AdminLogs.Count()
|
||||||
|
|
||||||
views := count("viewchunks")
|
views := count("viewchunks")
|
||||||
viewsAgents := count("viewchunks_agents")
|
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}
|
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}
|
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, basePage.Header, c.Panel{basePage, "panel_dashboard_right", "debug_page", "panel_debug", pi})
|
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 {
|
func DebugTasks(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError {
|
||||||
basePage, ferr := buildBasePage(w, r, user, "debug", "debug")
|
bp, ferr := buildBasePage(w, r, u, "debug", "debug")
|
||||||
if ferr != nil {
|
if ferr != nil {
|
||||||
return ferr
|
return ferr
|
||||||
}
|
}
|
||||||
|
|
||||||
var debugTasks []c.PanelDebugTaskTask
|
var tasks []c.PanelTaskTask
|
||||||
|
var taskTypes []c.PanelTaskType
|
||||||
|
|
||||||
pi := c.PanelDebugTaskPage{basePage, debugTasks}
|
pi := c.PanelTaskPage{bp, tasks, taskTypes}
|
||||||
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_dashboard_right", "debug_page", "panel_debug_task", pi})
|
return renderTemplate("panel", w, r, bp.Header, c.Panel{bp, "panel_dashboard_right", "debug_page", "panel_debug_task", pi})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue