add limit to index page, for performance improvements

This commit is contained in:
2025-01-07 11:40:59 +01:00
parent d5f934783b
commit fb257666aa
2 changed files with 22 additions and 20 deletions

View File

@@ -11,13 +11,14 @@ type ArticleModel struct {
// Gets all the article objects from the database. This may throw an error if
// the connection to the database fails.
func (m *ArticleModel) All() ([]model.Article, error) {
func (m *ArticleModel) All(limit int) ([]model.Article, error) {
stmt := `
SELECT id, title, sourceUrl, author, content, publishDate, fetchDate
FROM articles
ORDER BY publishDate DESC
LIMIT $1
`
rows, err := m.DB.Query(stmt)
rows, err := m.DB.Query(stmt, limit)
if err != nil {
return nil, err
}