parent
fb399ac973
commit
8b996803c8
5 changed files with 30 additions and 5 deletions
|
@ -29,6 +29,7 @@ type DB interface {
|
|||
GetNews(num int, days int) (news []New, err error)
|
||||
IncViews(ID string) error
|
||||
IncDownloads(ID string) error
|
||||
GetDownloadCounter(ID string) (int, error)
|
||||
GetFrontPage() FrontPage
|
||||
AddSubmission(submission Submission) (id int, err error)
|
||||
UpdateSubmission(id int, status string, book *Book) error
|
||||
|
@ -222,6 +223,7 @@ $$ LANGUAGE sql IMMUTABLE;
|
|||
-- Visits indexes
|
||||
CREATE INDEX IF NOT EXISTS visits_downloads_idx on visits(downloads DESC NULLS LAST);
|
||||
CREATE INDEX IF NOT EXISTS visits_views_idx on visits(views DESC NULLS LAST);
|
||||
CREATE INDEX IF NOT EXISTS visits_book_id_idx on visits(book_id);
|
||||
|
||||
-- Submissions indexes
|
||||
CREATE INDEX IF NOT EXISTS submissions_id_idx on submissions(submission_id);
|
||||
|
|
|
@ -93,6 +93,10 @@ func (db *roDB) IncDownloads(ID string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (db *roDB) GetDownloadCounter(ID string) (int, error) {
|
||||
return db.db.GetDownloadCounter(ID)
|
||||
}
|
||||
|
||||
func (db *roDB) GetFrontPage() FrontPage {
|
||||
return db.db.GetFrontPage()
|
||||
}
|
||||
|
|
|
@ -40,6 +40,15 @@ func (db *pgDB) IncDownloads(ID string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (db *pgDB) GetDownloadCounter(ID string) (int, error) {
|
||||
var num int
|
||||
err := db.sql.Model(&Visit{}).
|
||||
Column("downloads").
|
||||
Where("book_id = ?", ID).
|
||||
Select(&num)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (db *pgDB) GetFrontPage() FrontPage {
|
||||
return db.frontPage
|
||||
}
|
||||
|
|
Reference in a new issue