Cache front page results

This commit is contained in:
Las Zenow 2017-06-05 23:03:24 +00:00
parent f4ca9e2dbc
commit d40dc21627
5 changed files with 82 additions and 89 deletions

View file

@ -5,8 +5,6 @@ import (
"time"
"github.com/go-pg/pg"
log "github.com/cihub/seelog"
)
// Book metadata
@ -90,9 +88,6 @@ func (db *pgDB) getBooks(active bool, query string, length int, start int) (book
Offset(start).
Limit(length).
SelectAndCountEstimate(1000)
if query == "" && active {
num = db.bookCount
}
return books, num, err
}
@ -170,28 +165,6 @@ func (db *pgDB) IsBookActive(id string) bool {
return active[0]
}
func (db *pgDB) updateCounter() {
var count int
err := db.sql.Model(&Book{}).
ColumnExpr("count(*)").
Where("active = true").
Select(&count)
if err != nil {
log.Error("Error updating count: ", err)
} else {
db.bookCount = count
}
}
func (db *pgDB) countUpdater() {
periodicity := 61 * time.Minute
for true {
db.updateCounter()
time.Sleep(periodicity)
}
}
type columnq struct {
column string
value string