Improve memory footprint on upload books
This commit is contained in:
parent
04b636a62c
commit
548bcd3b70
2 changed files with 51 additions and 49 deletions
64
lib/stats.go
64
lib/stats.go
|
@ -108,35 +108,39 @@ type statsRequest struct {
|
|||
|
||||
func (sg StatsGatherer) worker() {
|
||||
for req := range sg.channel {
|
||||
var err error
|
||||
id := mux.Vars(req.r)["id"]
|
||||
search := strings.Join(req.r.Form["q"], " ")
|
||||
fmt := req.r.FormValue("fmt")
|
||||
pattern := strings.Split(req.r.URL.Path, "/")
|
||||
|
||||
section := "/"
|
||||
if len(pattern) > 1 && pattern[1] != "" {
|
||||
section = pattern[1]
|
||||
}
|
||||
|
||||
sg.instrument.Request(instrument.RequestData{
|
||||
Section: section,
|
||||
ID: id,
|
||||
Search: search,
|
||||
Fmt: fmt,
|
||||
Duration: req.duration,
|
||||
})
|
||||
switch section {
|
||||
case "download":
|
||||
err = sg.db.IncDownloads(id)
|
||||
case "book":
|
||||
err = sg.db.IncViews(id)
|
||||
case "read":
|
||||
err = sg.db.IncViews(id)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Warn("Problem incrementing visits: ", err)
|
||||
}
|
||||
sg.save(req)
|
||||
}
|
||||
}
|
||||
|
||||
func (sg StatsGatherer) save(req statsRequest) {
|
||||
var err error
|
||||
id := mux.Vars(req.r)["id"]
|
||||
search := strings.Join(req.r.Form["q"], " ")
|
||||
fmt := req.r.FormValue("fmt")
|
||||
pattern := strings.Split(req.r.URL.Path, "/")
|
||||
|
||||
section := "/"
|
||||
if len(pattern) > 1 && pattern[1] != "" {
|
||||
section = pattern[1]
|
||||
}
|
||||
|
||||
sg.instrument.Request(instrument.RequestData{
|
||||
Section: section,
|
||||
ID: id,
|
||||
Search: search,
|
||||
Fmt: fmt,
|
||||
Duration: req.duration,
|
||||
})
|
||||
switch section {
|
||||
case "download":
|
||||
err = sg.db.IncDownloads(id)
|
||||
case "book":
|
||||
err = sg.db.IncViews(id)
|
||||
case "read":
|
||||
err = sg.db.IncViews(id)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Warn("Problem incrementing visits: ", err)
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue