Proper pagination.

This commit is contained in:
Stanislav Nikitin 2018-05-17 22:16:07 +05:00
parent ec2e885438
commit abf10c0904

View File

@ -66,7 +66,7 @@ func GetPagedPastes(page int) ([]Paste, error) {
func GetPastesPages() int { func GetPastesPages() int {
var pastesCount int var pastesCount int
dbConn := c.Database.GetDatabaseConnection() dbConn := c.Database.GetDatabaseConnection()
err := dbConn.Get(&pastesCount, "SELECT COUNT(id) FROM `pastes`") err := dbConn.Get(&pastesCount, "SELECT COUNT(id) FROM `pastes` WHERE private != true")
if err != nil { if err != nil {
return 1 return 1
} }
@ -74,8 +74,8 @@ func GetPastesPages() int {
// Calculate pages. // Calculate pages.
pages := pastesCount / PAGINATION pages := pastesCount / PAGINATION
// Check if we have any remainder. Add 1 to pages count if so. // Check if we have any remainder. Add 1 to pages count if so.
if pastesCount%PAGINATION != 0 { if pastesCount%PAGINATION > 0 {
pages += 1 pages++
} }
return pages return pages