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

@ -26,19 +26,25 @@ type DB interface {
GetNews(num int, days int) (news []New, err error)
IncViews(ID string) error
IncDownloads(ID string) error
GetVisitedBooks(num int) (books []Book, err error)
GetDownloadedBooks(num int) (books []Book, err error)
GetTags() ([]string, error)
GetFrontPage() FrontPage
}
const (
tagsDisplay = 50
tagsDisplay = 50
booksFrontPage = 6
)
type pgDB struct {
sql *pg.DB
tags []string
bookCount int
frontPage FrontPage
}
type FrontPage struct {
Count int
Last []Book
Visited []Book
Download []Book
Tags []string
}
// Options for the database
@ -66,8 +72,7 @@ func Init(options Options) (DB, error) {
var db pgDB
db.sql = sql
go db.tagUpdater()
go db.countUpdater()
go db.frontPageUpdater()
return &db, nil
}