Rename helper packages

This commit is contained in:
Frédéric Guillot 2018-01-02 19:15:08 -08:00
parent 3c3f397bf5
commit c39f2e1a8d
31 changed files with 97 additions and 97 deletions

View file

@ -1,8 +1,8 @@
// Copyright 2017 Frédéric Guillot. All rights reserved. // Copyright 2018 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0 // Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package helper package crypto
import ( import (
"crypto/rand" "crypto/rand"

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT License // Use of this source code is governed by the MIT License
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
package helper package duration
import ( import (
"math" "math"
@ -26,9 +26,9 @@ var (
Years = `%d years ago` Years = `%d years ago`
) )
// GetElapsedTime returns in a human readable format the elapsed time // ElapsedTime returns in a human readable format the elapsed time
// since the given datetime. // since the given datetime.
func GetElapsedTime(translator *locale.Language, t time.Time) string { func ElapsedTime(translator *locale.Language, t time.Time) string {
if t.IsZero() || time.Now().Before(t) { if t.IsZero() || time.Now().Before(t) {
return translator.Get(NotYet) return translator.Get(NotYet)
} }

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT License // Use of this source code is governed by the MIT License
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
package helper package duration
import ( import (
"fmt" "fmt"
@ -31,7 +31,7 @@ func TestElapsedTime(t *testing.T) {
{time.Now().Add(-time.Hour * 24 * 365 * 3), fmt.Sprintf(Years, 3)}, {time.Now().Add(-time.Hour * 24 * 365 * 3), fmt.Sprintf(Years, 3)},
} }
for i, tt := range dt { for i, tt := range dt {
if out := GetElapsedTime(&locale.Language{}, tt.in); out != tt.out { if out := ElapsedTime(&locale.Language{}, tt.in); out != tt.out {
t.Errorf("%d. content mismatch for %v:exp=%q got=%q", i, tt.in, tt.out, out) t.Errorf("%d. content mismatch for %v:exp=%q got=%q", i, tt.in, tt.out, out)
} }
} }

View file

@ -15,8 +15,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/timer"
) )
// Note: Some websites have a user agent filter. // Note: Some websites have a user agent filter.
@ -73,7 +73,7 @@ func (c *Client) PostJSON(data interface{}) (*Response, error) {
} }
func (c *Client) executeRequest(request *http.Request) (*Response, error) { func (c *Client) executeRequest(request *http.Request) (*Response, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[HttpClient] url=%s", c.url)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[HttpClient] url=%s", c.url))
client := c.buildClient() client := c.buildClient()
resp, err := client.Do(request) resp, err := client.Do(request)

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// 2017-12-29 14:34:59.486421907 -0800 PST m=+0.007402806 // 2017-12-31 18:38:42.071995118 -0800 PST m=+0.052826276
package locale package locale

View file

@ -10,7 +10,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/reader/date" "github.com/miniflux/miniflux/reader/date"
@ -163,7 +163,7 @@ func getContent(a *atomEntry) string {
func getHash(a *atomEntry) string { func getHash(a *atomEntry) string {
for _, value := range []string{a.ID, getURL(a.Links)} { for _, value := range []string{a.ID, getURL(a.Links)} {
if value != "" { if value != "" {
return helper.Hash(value) return crypto.Hash(value)
} }
} }

View file

@ -9,13 +9,13 @@ import (
"time" "time"
"github.com/miniflux/miniflux/errors" "github.com/miniflux/miniflux/errors"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/http" "github.com/miniflux/miniflux/http"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/reader/icon" "github.com/miniflux/miniflux/reader/icon"
"github.com/miniflux/miniflux/reader/processor" "github.com/miniflux/miniflux/reader/processor"
"github.com/miniflux/miniflux/storage" "github.com/miniflux/miniflux/storage"
"github.com/miniflux/miniflux/timer"
) )
var ( var (
@ -34,7 +34,7 @@ type Handler struct {
// CreateFeed fetch, parse and store a new feed. // CreateFeed fetch, parse and store a new feed.
func (h *Handler) CreateFeed(userID, categoryID int64, url string, crawler bool) (*model.Feed, error) { func (h *Handler) CreateFeed(userID, categoryID int64, url string, crawler bool) (*model.Feed, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Handler:CreateFeed] feedUrl=%s", url)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Handler:CreateFeed] feedUrl=%s", url))
if !h.store.CategoryExists(userID, categoryID) { if !h.store.CategoryExists(userID, categoryID) {
return nil, errors.NewLocalizedError(errCategoryNotFound) return nil, errors.NewLocalizedError(errCategoryNotFound)
@ -96,7 +96,7 @@ func (h *Handler) CreateFeed(userID, categoryID int64, url string, crawler bool)
// RefreshFeed fetch and update a feed if necessary. // RefreshFeed fetch and update a feed if necessary.
func (h *Handler) RefreshFeed(userID, feedID int64) error { func (h *Handler) RefreshFeed(userID, feedID int64) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Handler:RefreshFeed] feedID=%d", feedID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Handler:RefreshFeed] feedID=%d", feedID))
originalFeed, err := h.store.FeedByID(userID, feedID) originalFeed, err := h.store.FeedByID(userID, feedID)
if err != nil { if err != nil {

View file

@ -12,12 +12,12 @@ import (
"strings" "strings"
"time" "time"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/reader/atom" "github.com/miniflux/miniflux/reader/atom"
"github.com/miniflux/miniflux/reader/json" "github.com/miniflux/miniflux/reader/json"
"github.com/miniflux/miniflux/reader/rdf" "github.com/miniflux/miniflux/reader/rdf"
"github.com/miniflux/miniflux/reader/rss" "github.com/miniflux/miniflux/reader/rss"
"github.com/miniflux/miniflux/timer"
"golang.org/x/net/html/charset" "golang.org/x/net/html/charset"
) )
@ -33,7 +33,7 @@ const (
// DetectFeedFormat detect feed format from input data. // DetectFeedFormat detect feed format from input data.
func DetectFeedFormat(data io.Reader) string { func DetectFeedFormat(data io.Reader) string {
defer helper.ExecutionTime(time.Now(), "[Feed:DetectFeedFormat]") defer timer.ExecutionTime(time.Now(), "[Feed:DetectFeedFormat]")
var buffer bytes.Buffer var buffer bytes.Buffer
tee := io.TeeReader(data, &buffer) tee := io.TeeReader(data, &buffer)
@ -67,7 +67,7 @@ func DetectFeedFormat(data io.Reader) string {
} }
func parseFeed(data io.Reader) (*model.Feed, error) { func parseFeed(data io.Reader) (*model.Feed, error) {
defer helper.ExecutionTime(time.Now(), "[Feed:ParseFeed]") defer timer.ExecutionTime(time.Now(), "[Feed:ParseFeed]")
var buffer bytes.Buffer var buffer bytes.Buffer
io.Copy(&buffer, data) io.Copy(&buffer, data)

View file

@ -11,7 +11,7 @@ import (
"io/ioutil" "io/ioutil"
"strings" "strings"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/http" "github.com/miniflux/miniflux/http"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
@ -107,7 +107,7 @@ func downloadIcon(iconURL string) (*model.Icon, error) {
} }
icon := &model.Icon{ icon := &model.Icon{
Hash: helper.HashFromBytes(body), Hash: crypto.HashFromBytes(body),
MimeType: response.ContentType, MimeType: response.ContentType,
Content: body, Content: body,
} }
@ -146,7 +146,7 @@ func parseImageDataURL(value string) (*model.Icon, error) {
} }
icon := &model.Icon{ icon := &model.Icon{
Hash: helper.HashFromBytes(blob), Hash: crypto.HashFromBytes(blob),
Content: blob, Content: blob,
MimeType: mimeType, MimeType: mimeType,
} }

View file

@ -8,7 +8,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/reader/date" "github.com/miniflux/miniflux/reader/date"
@ -105,7 +105,7 @@ func (j *jsonItem) GetAuthor() string {
func (j *jsonItem) GetHash() string { func (j *jsonItem) GetHash() string {
for _, value := range []string{j.ID, j.URL, j.Text + j.HTML + j.Summary} { for _, value := range []string{j.ID, j.URL, j.Text + j.HTML + j.Summary} {
if value != "" { if value != "" {
return helper.Hash(value) return crypto.Hash(value)
} }
} }

View file

@ -9,7 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/reader/sanitizer" "github.com/miniflux/miniflux/reader/sanitizer"
"github.com/miniflux/miniflux/url" "github.com/miniflux/miniflux/url"
@ -73,5 +73,5 @@ func getHash(r *rdfItem) string {
value = r.Title + r.Description value = r.Title + r.Description
} }
return helper.Hash(value) return crypto.Hash(value)
} }

View file

@ -11,7 +11,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/reader/date" "github.com/miniflux/miniflux/reader/date"
@ -157,7 +157,7 @@ func (r *rssItem) GetAuthor() string {
func (r *rssItem) GetHash() string { func (r *rssItem) GetHash() string {
for _, value := range []string{r.GUID, r.GetURL()} { for _, value := range []string{r.GUID, r.GetURL()} {
if value != "" { if value != "" {
return helper.Hash(value) return crypto.Hash(value)
} }
} }

View file

@ -11,10 +11,10 @@ import (
"time" "time"
"github.com/miniflux/miniflux/errors" "github.com/miniflux/miniflux/errors"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/http" "github.com/miniflux/miniflux/http"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/reader/feed" "github.com/miniflux/miniflux/reader/feed"
"github.com/miniflux/miniflux/timer"
"github.com/miniflux/miniflux/url" "github.com/miniflux/miniflux/url"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
@ -27,7 +27,7 @@ var (
// FindSubscriptions downloads and try to find one or more subscriptions from an URL. // FindSubscriptions downloads and try to find one or more subscriptions from an URL.
func FindSubscriptions(websiteURL string) (Subscriptions, error) { func FindSubscriptions(websiteURL string) (Subscriptions, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[FindSubscriptions] url=%s", websiteURL)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[FindSubscriptions] url=%s", websiteURL))
client := http.NewClient(websiteURL) client := http.NewClient(websiteURL)
response, err := client.Get() response, err := client.Get()

View file

@ -7,7 +7,7 @@ package core
import ( import (
"net/http" "net/http"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/locale" "github.com/miniflux/miniflux/locale"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
@ -111,7 +111,7 @@ func (c *Context) OAuth2State() string {
// GenerateOAuth2State generate a new OAuth2 state. // GenerateOAuth2State generate a new OAuth2 state.
func (c *Context) GenerateOAuth2State() string { func (c *Context) GenerateOAuth2State() string {
state := helper.GenerateRandomString(32) state := crypto.GenerateRandomString(32)
c.store.UpdateSessionField(c.SessionID(), "oauth2_state", state) c.store.UpdateSessionField(c.SessionID(), "oauth2_state", state)
return state return state
} }

View file

@ -9,12 +9,12 @@ import (
"time" "time"
"github.com/miniflux/miniflux/config" "github.com/miniflux/miniflux/config"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/locale" "github.com/miniflux/miniflux/locale"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/server/middleware" "github.com/miniflux/miniflux/server/middleware"
"github.com/miniflux/miniflux/server/template" "github.com/miniflux/miniflux/server/template"
"github.com/miniflux/miniflux/storage" "github.com/miniflux/miniflux/storage"
"github.com/miniflux/miniflux/timer"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/tomasen/realip" "github.com/tomasen/realip"
@ -36,7 +36,7 @@ type Handler struct {
// Use is a wrapper around an HTTP handler. // Use is a wrapper around an HTTP handler.
func (h *Handler) Use(f HandlerFunc) http.Handler { func (h *Handler) Use(f HandlerFunc) http.Handler {
return h.middleware.WrapFunc(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return h.middleware.WrapFunc(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer helper.ExecutionTime(time.Now(), r.URL.Path) defer timer.ExecutionTime(time.Now(), r.URL.Path)
logger.Debug("[HTTP] %s %s %s", realip.RealIP(r), r.Method, r.URL.Path) logger.Debug("[HTTP] %s %s %s", realip.RealIP(r), r.Method, r.URL.Path)
if r.Header.Get("X-Forwarded-Proto") == "https" { if r.Header.Get("X-Forwarded-Proto") == "https" {

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// 2017-12-28 18:55:07.408638507 -0800 PST m=+0.035359093 // 2017-12-31 18:38:42.07097409 -0800 PST m=+0.051805248
package template package template

View file

@ -13,11 +13,11 @@ import (
"time" "time"
"github.com/miniflux/miniflux/config" "github.com/miniflux/miniflux/config"
"github.com/miniflux/miniflux/duration"
"github.com/miniflux/miniflux/errors" "github.com/miniflux/miniflux/errors"
"github.com/miniflux/miniflux/locale" "github.com/miniflux/miniflux/locale"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/server/route" "github.com/miniflux/miniflux/server/route"
"github.com/miniflux/miniflux/server/template/helper"
"github.com/miniflux/miniflux/server/ui/filter" "github.com/miniflux/miniflux/server/ui/filter"
"github.com/miniflux/miniflux/url" "github.com/miniflux/miniflux/url"
@ -83,7 +83,7 @@ func (e *Engine) parseAll() {
return ts.Format("2006-01-02 15:04:05") return ts.Format("2006-01-02 15:04:05")
}, },
"elapsed": func(ts time.Time) string { "elapsed": func(ts time.Time) string {
return helper.GetElapsedTime(e.currentLocale, ts) return duration.ElapsedTime(e.currentLocale, ts)
}, },
"t": func(key interface{}, args ...interface{}) string { "t": func(key interface{}, args ...interface{}) string {
switch key.(type) { switch key.(type) {

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// 2017-12-28 19:08:21.190684499 -0800 PST m=+0.036802540 // 2017-12-31 18:38:42.048775793 -0800 PST m=+0.029606951
package template package template

View file

@ -10,7 +10,7 @@ import (
"io/ioutil" "io/ioutil"
"time" "time"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/http" "github.com/miniflux/miniflux/http"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/server/core" "github.com/miniflux/miniflux/server/core"
@ -50,7 +50,7 @@ func (c *Controller) ImageProxy(ctx *core.Context, request *core.Request, respon
} }
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
etag := helper.HashFromBytes(body) etag := crypto.HashFromBytes(body)
response.Cache(resp.ContentType, etag, body, 72*time.Hour) response.Cache(resp.ContentType, etag, body, 72*time.Hour)
} }

View file

@ -10,13 +10,13 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/timer"
) )
// AnotherCategoryExists checks if another category exists with the same title. // AnotherCategoryExists checks if another category exists with the same title.
func (s *Storage) AnotherCategoryExists(userID, categoryID int64, title string) bool { func (s *Storage) AnotherCategoryExists(userID, categoryID int64, title string) bool {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherCategoryExists] userID=%d, categoryID=%d, title=%s", userID, categoryID, title)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherCategoryExists] userID=%d, categoryID=%d, title=%s", userID, categoryID, title))
var result int var result int
query := `SELECT count(*) as c FROM categories WHERE user_id=$1 AND id != $2 AND title=$3` query := `SELECT count(*) as c FROM categories WHERE user_id=$1 AND id != $2 AND title=$3`
@ -26,7 +26,7 @@ func (s *Storage) AnotherCategoryExists(userID, categoryID int64, title string)
// CategoryExists checks if the given category exists into the database. // CategoryExists checks if the given category exists into the database.
func (s *Storage) CategoryExists(userID, categoryID int64) bool { func (s *Storage) CategoryExists(userID, categoryID int64) bool {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryExists] userID=%d, categoryID=%d", userID, categoryID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryExists] userID=%d, categoryID=%d", userID, categoryID))
var result int var result int
query := `SELECT count(*) as c FROM categories WHERE user_id=$1 AND id=$2` query := `SELECT count(*) as c FROM categories WHERE user_id=$1 AND id=$2`
@ -36,7 +36,7 @@ func (s *Storage) CategoryExists(userID, categoryID int64) bool {
// Category returns a category from the database. // Category returns a category from the database.
func (s *Storage) Category(userID, categoryID int64) (*model.Category, error) { func (s *Storage) Category(userID, categoryID int64) (*model.Category, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Category] userID=%d, getCategory=%d", userID, categoryID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Category] userID=%d, getCategory=%d", userID, categoryID))
var category model.Category var category model.Category
query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 AND id=$2` query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 AND id=$2`
@ -52,7 +52,7 @@ func (s *Storage) Category(userID, categoryID int64) (*model.Category, error) {
// FirstCategory returns the first category for the given user. // FirstCategory returns the first category for the given user.
func (s *Storage) FirstCategory(userID int64) (*model.Category, error) { func (s *Storage) FirstCategory(userID int64) (*model.Category, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FirstCategory] userID=%d", userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FirstCategory] userID=%d", userID))
var category model.Category var category model.Category
query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 ORDER BY title ASC LIMIT 1` query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 ORDER BY title ASC LIMIT 1`
@ -68,7 +68,7 @@ func (s *Storage) FirstCategory(userID int64) (*model.Category, error) {
// CategoryByTitle finds a category by the title. // CategoryByTitle finds a category by the title.
func (s *Storage) CategoryByTitle(userID int64, title string) (*model.Category, error) { func (s *Storage) CategoryByTitle(userID int64, title string) (*model.Category, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryByTitle] userID=%d, title=%s", userID, title)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryByTitle] userID=%d, title=%s", userID, title))
var category model.Category var category model.Category
query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 AND title=$2` query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 AND title=$2`
@ -84,7 +84,7 @@ func (s *Storage) CategoryByTitle(userID int64, title string) (*model.Category,
// Categories returns all categories that belongs to the given user. // Categories returns all categories that belongs to the given user.
func (s *Storage) Categories(userID int64) (model.Categories, error) { func (s *Storage) Categories(userID int64) (model.Categories, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Categories] userID=%d", userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Categories] userID=%d", userID))
query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 ORDER BY title ASC` query := `SELECT id, user_id, title FROM categories WHERE user_id=$1 ORDER BY title ASC`
rows, err := s.db.Query(query, userID) rows, err := s.db.Query(query, userID)
@ -108,7 +108,7 @@ func (s *Storage) Categories(userID int64) (model.Categories, error) {
// CategoriesWithFeedCount returns all categories with the number of feeds. // CategoriesWithFeedCount returns all categories with the number of feeds.
func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error) { func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoriesWithFeedCount] userID=%d", userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoriesWithFeedCount] userID=%d", userID))
query := `SELECT query := `SELECT
c.id, c.user_id, c.title, c.id, c.user_id, c.title,
(SELECT count(*) FROM feeds WHERE feeds.category_id=c.id) AS count (SELECT count(*) FROM feeds WHERE feeds.category_id=c.id) AS count
@ -135,7 +135,7 @@ func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error
// CreateCategory creates a new category. // CreateCategory creates a new category.
func (s *Storage) CreateCategory(category *model.Category) error { func (s *Storage) CreateCategory(category *model.Category) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateCategory] title=%s", category.Title)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateCategory] title=%s", category.Title))
query := ` query := `
INSERT INTO categories INSERT INTO categories
@ -159,7 +159,7 @@ func (s *Storage) CreateCategory(category *model.Category) error {
// UpdateCategory updates an existing category. // UpdateCategory updates an existing category.
func (s *Storage) UpdateCategory(category *model.Category) error { func (s *Storage) UpdateCategory(category *model.Category) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateCategory] categoryID=%d", category.ID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateCategory] categoryID=%d", category.ID))
query := `UPDATE categories SET title=$1 WHERE id=$2 AND user_id=$3` query := `UPDATE categories SET title=$1 WHERE id=$2 AND user_id=$3`
_, err := s.db.Exec( _, err := s.db.Exec(
@ -178,7 +178,7 @@ func (s *Storage) UpdateCategory(category *model.Category) error {
// RemoveCategory deletes a category. // RemoveCategory deletes a category.
func (s *Storage) RemoveCategory(userID, categoryID int64) error { func (s *Storage) RemoveCategory(userID, categoryID int64) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveCategory] userID=%d, categoryID=%d", userID, categoryID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveCategory] userID=%d, categoryID=%d", userID, categoryID))
result, err := s.db.Exec("DELETE FROM categories WHERE id = $1 AND user_id = $2", categoryID, userID) result, err := s.db.Exec("DELETE FROM categories WHERE id = $1 AND user_id = $2", categoryID, userID)
if err != nil { if err != nil {

View file

@ -9,9 +9,9 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/timer"
"github.com/lib/pq" "github.com/lib/pq"
) )
@ -159,7 +159,7 @@ func (s *Storage) cleanupEntries(feedID int64, entryHashes []string) error {
// SetEntriesStatus update the status of the given list of entries. // SetEntriesStatus update the status of the given list of entries.
func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string) error { func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetEntriesStatus] userID=%d, entryIDs=%v, status=%s", userID, entryIDs, status)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetEntriesStatus] userID=%d, entryIDs=%v, status=%s", userID, entryIDs, status))
query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND id=ANY($3)` query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND id=ANY($3)`
result, err := s.db.Exec(query, status, userID, pq.Array(entryIDs)) result, err := s.db.Exec(query, status, userID, pq.Array(entryIDs))
@ -181,7 +181,7 @@ func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string
// ToggleBookmark toggles entry bookmark value. // ToggleBookmark toggles entry bookmark value.
func (s *Storage) ToggleBookmark(userID int64, entryID int64) error { func (s *Storage) ToggleBookmark(userID int64, entryID int64) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:ToggleBookmark] userID=%d, entryID=%d", userID, entryID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:ToggleBookmark] userID=%d, entryID=%d", userID, entryID))
query := `UPDATE entries SET starred = NOT starred WHERE user_id=$1 AND id=$2` query := `UPDATE entries SET starred = NOT starred WHERE user_id=$1 AND id=$2`
result, err := s.db.Exec(query, userID, entryID) result, err := s.db.Exec(query, userID, entryID)
@ -203,7 +203,7 @@ func (s *Storage) ToggleBookmark(userID int64, entryID int64) error {
// FlushHistory set all entries with the status "read" to "removed". // FlushHistory set all entries with the status "read" to "removed".
func (s *Storage) FlushHistory(userID int64) error { func (s *Storage) FlushHistory(userID int64) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FlushHistory] userID=%d", userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FlushHistory] userID=%d", userID))
query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND status=$3 AND starred='f'` query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND status=$3 AND starred='f'`
_, err := s.db.Exec(query, model.EntryStatusRemoved, userID, model.EntryStatusRead) _, err := s.db.Exec(query, model.EntryStatusRemoved, userID, model.EntryStatusRead)

View file

@ -11,8 +11,8 @@ import (
"github.com/lib/pq" "github.com/lib/pq"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/timer"
) )
// EntryQueryBuilder builds a SQL query to fetch entries. // EntryQueryBuilder builds a SQL query to fetch entries.
@ -114,7 +114,7 @@ func (e *EntryQueryBuilder) WithOffset(offset int) *EntryQueryBuilder {
// CountEntries count the number of entries that match the condition. // CountEntries count the number of entries that match the condition.
func (e *EntryQueryBuilder) CountEntries() (count int, err error) { func (e *EntryQueryBuilder) CountEntries() (count int, err error) {
defer helper.ExecutionTime( defer timer.ExecutionTime(
time.Now(), time.Now(),
fmt.Sprintf("[EntryQueryBuilder:CountEntries] userID=%d, feedID=%d, status=%s", e.userID, e.feedID, e.status), fmt.Sprintf("[EntryQueryBuilder:CountEntries] userID=%d, feedID=%d, status=%s", e.userID, e.feedID, e.status),
) )
@ -152,7 +152,7 @@ func (e *EntryQueryBuilder) GetEntry() (*model.Entry, error) {
// GetEntries returns a list of entries that match the condition. // GetEntries returns a list of entries that match the condition.
func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) {
debugStr := "[EntryQueryBuilder:GetEntries] userID=%d, feedID=%d, categoryID=%d, status=%s, order=%s, direction=%s, offset=%d, limit=%d" debugStr := "[EntryQueryBuilder:GetEntries] userID=%d, feedID=%d, categoryID=%d, status=%s, order=%s, direction=%s, offset=%d, limit=%d"
defer helper.ExecutionTime(time.Now(), fmt.Sprintf(debugStr, e.userID, e.feedID, e.categoryID, e.status, e.order, e.direction, e.offset, e.limit)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf(debugStr, e.userID, e.feedID, e.categoryID, e.status, e.order, e.direction, e.offset, e.limit))
query := ` query := `
SELECT SELECT
@ -233,7 +233,7 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) {
// GetEntryIDs returns a list of entry IDs that match the condition. // GetEntryIDs returns a list of entry IDs that match the condition.
func (e *EntryQueryBuilder) GetEntryIDs() ([]int64, error) { func (e *EntryQueryBuilder) GetEntryIDs() ([]int64, error) {
debugStr := "[EntryQueryBuilder:GetEntryIDs] userID=%d, feedID=%d, categoryID=%d, status=%s, order=%s, direction=%s, offset=%d, limit=%d" debugStr := "[EntryQueryBuilder:GetEntryIDs] userID=%d, feedID=%d, categoryID=%d, status=%s, order=%s, direction=%s, offset=%d, limit=%d"
defer helper.ExecutionTime(time.Now(), fmt.Sprintf(debugStr, e.userID, e.feedID, e.categoryID, e.status, e.order, e.direction, e.offset, e.limit)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf(debugStr, e.userID, e.feedID, e.categoryID, e.status, e.order, e.direction, e.offset, e.limit))
query := ` query := `
SELECT SELECT

View file

@ -10,13 +10,13 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/timer"
) )
// FeedExists checks if the given feed exists. // FeedExists checks if the given feed exists.
func (s *Storage) FeedExists(userID, feedID int64) bool { func (s *Storage) FeedExists(userID, feedID int64) bool {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedExists] userID=%d, feedID=%d", userID, feedID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedExists] userID=%d, feedID=%d", userID, feedID))
var result int var result int
query := `SELECT count(*) as c FROM feeds WHERE user_id=$1 AND id=$2` query := `SELECT count(*) as c FROM feeds WHERE user_id=$1 AND id=$2`
@ -26,7 +26,7 @@ func (s *Storage) FeedExists(userID, feedID int64) bool {
// FeedURLExists checks if feed URL already exists. // FeedURLExists checks if feed URL already exists.
func (s *Storage) FeedURLExists(userID int64, feedURL string) bool { func (s *Storage) FeedURLExists(userID int64, feedURL string) bool {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedURLExists] userID=%d, feedURL=%s", userID, feedURL)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedURLExists] userID=%d, feedURL=%s", userID, feedURL))
var result int var result int
query := `SELECT count(*) as c FROM feeds WHERE user_id=$1 AND feed_url=$2` query := `SELECT count(*) as c FROM feeds WHERE user_id=$1 AND feed_url=$2`
@ -47,7 +47,7 @@ func (s *Storage) CountFeeds(userID int64) int {
// Feeds returns all feeds of the given user. // Feeds returns all feeds of the given user.
func (s *Storage) Feeds(userID int64) (model.Feeds, error) { func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Feeds] userID=%d", userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Feeds] userID=%d", userID))
feeds := make(model.Feeds, 0) feeds := make(model.Feeds, 0)
query := `SELECT query := `SELECT
@ -110,7 +110,7 @@ func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
// FeedByID returns a feed by the ID. // FeedByID returns a feed by the ID.
func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) { func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedByID] feedID=%d", feedID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedByID] feedID=%d", feedID))
var feed model.Feed var feed model.Feed
var iconID interface{} var iconID interface{}
@ -165,7 +165,7 @@ func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) {
// CreateFeed creates a new feed. // CreateFeed creates a new feed.
func (s *Storage) CreateFeed(feed *model.Feed) error { func (s *Storage) CreateFeed(feed *model.Feed) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateFeed] feedURL=%s", feed.FeedURL)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateFeed] feedURL=%s", feed.FeedURL))
sql := ` sql := `
INSERT INTO feeds INSERT INTO feeds
(feed_url, site_url, title, category_id, user_id, etag_header, last_modified_header, crawler) (feed_url, site_url, title, category_id, user_id, etag_header, last_modified_header, crawler)
@ -202,7 +202,7 @@ func (s *Storage) CreateFeed(feed *model.Feed) error {
// UpdateFeed updates an existing feed. // UpdateFeed updates an existing feed.
func (s *Storage) UpdateFeed(feed *model.Feed) (err error) { func (s *Storage) UpdateFeed(feed *model.Feed) (err error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateFeed] feedURL=%s", feed.FeedURL)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateFeed] feedURL=%s", feed.FeedURL))
query := `UPDATE feeds SET query := `UPDATE feeds SET
feed_url=$1, site_url=$2, title=$3, category_id=$4, etag_header=$5, last_modified_header=$6, checked_at=$7, feed_url=$1, site_url=$2, title=$3, category_id=$4, etag_header=$5, last_modified_header=$6, checked_at=$7,
@ -235,7 +235,7 @@ func (s *Storage) UpdateFeed(feed *model.Feed) (err error) {
// RemoveFeed removes a feed. // RemoveFeed removes a feed.
func (s *Storage) RemoveFeed(userID, feedID int64) error { func (s *Storage) RemoveFeed(userID, feedID int64) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveFeed] userID=%d, feedID=%d", userID, feedID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveFeed] userID=%d, feedID=%d", userID, feedID))
result, err := s.db.Exec("DELETE FROM feeds WHERE id = $1 AND user_id = $2", feedID, userID) result, err := s.db.Exec("DELETE FROM feeds WHERE id = $1 AND user_id = $2", feedID, userID)
if err != nil { if err != nil {

View file

@ -10,8 +10,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/timer"
) )
// HasIcon checks if the given feed has an icon. // HasIcon checks if the given feed has an icon.
@ -24,7 +24,7 @@ func (s *Storage) HasIcon(feedID int64) bool {
// IconByID returns an icon by the ID. // IconByID returns an icon by the ID.
func (s *Storage) IconByID(iconID int64) (*model.Icon, error) { func (s *Storage) IconByID(iconID int64) (*model.Icon, error) {
defer helper.ExecutionTime(time.Now(), "[Storage:IconByID]") defer timer.ExecutionTime(time.Now(), "[Storage:IconByID]")
var icon model.Icon var icon model.Icon
query := `SELECT id, hash, mime_type, content FROM icons WHERE id=$1` query := `SELECT id, hash, mime_type, content FROM icons WHERE id=$1`
@ -40,7 +40,7 @@ func (s *Storage) IconByID(iconID int64) (*model.Icon, error) {
// IconByFeedID returns a feed icon. // IconByFeedID returns a feed icon.
func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error) { func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:IconByFeedID] userID=%d, feedID=%d", userID, feedID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:IconByFeedID] userID=%d, feedID=%d", userID, feedID))
query := ` query := `
SELECT SELECT
icons.id, icons.hash, icons.mime_type, icons.content icons.id, icons.hash, icons.mime_type, icons.content
@ -62,7 +62,7 @@ func (s *Storage) IconByFeedID(userID, feedID int64) (*model.Icon, error) {
// IconByHash returns an icon by the hash (checksum). // IconByHash returns an icon by the hash (checksum).
func (s *Storage) IconByHash(icon *model.Icon) error { func (s *Storage) IconByHash(icon *model.Icon) error {
defer helper.ExecutionTime(time.Now(), "[Storage:IconByHash]") defer timer.ExecutionTime(time.Now(), "[Storage:IconByHash]")
err := s.db.QueryRow(`SELECT id FROM icons WHERE hash=$1`, icon.Hash).Scan(&icon.ID) err := s.db.QueryRow(`SELECT id FROM icons WHERE hash=$1`, icon.Hash).Scan(&icon.ID)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
@ -76,7 +76,7 @@ func (s *Storage) IconByHash(icon *model.Icon) error {
// CreateIcon creates a new icon. // CreateIcon creates a new icon.
func (s *Storage) CreateIcon(icon *model.Icon) error { func (s *Storage) CreateIcon(icon *model.Icon) error {
defer helper.ExecutionTime(time.Now(), "[Storage:CreateIcon]") defer timer.ExecutionTime(time.Now(), "[Storage:CreateIcon]")
query := ` query := `
INSERT INTO icons INSERT INTO icons
@ -101,7 +101,7 @@ func (s *Storage) CreateIcon(icon *model.Icon) error {
// CreateFeedIcon creates an icon and associate the icon to the given feed. // CreateFeedIcon creates an icon and associate the icon to the given feed.
func (s *Storage) CreateFeedIcon(feed *model.Feed, icon *model.Icon) error { func (s *Storage) CreateFeedIcon(feed *model.Feed, icon *model.Icon) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateFeedIcon] feedID=%d", feed.ID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateFeedIcon] feedID=%d", feed.ID))
err := s.IconByHash(icon) err := s.IconByHash(icon)
if err != nil { if err != nil {
@ -125,7 +125,7 @@ func (s *Storage) CreateFeedIcon(feed *model.Feed, icon *model.Icon) error {
// Icons returns all icons tht belongs to a user. // Icons returns all icons tht belongs to a user.
func (s *Storage) Icons(userID int64) (model.Icons, error) { func (s *Storage) Icons(userID int64) (model.Icons, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Icons] userID=%d", userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Icons] userID=%d", userID))
query := ` query := `
SELECT SELECT
icons.id, icons.hash, icons.mime_type, icons.content icons.id, icons.hash, icons.mime_type, icons.content

View file

@ -8,15 +8,15 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/timer"
) )
const maxParsingError = 3 const maxParsingError = 3
// NewBatch returns a serie of jobs. // NewBatch returns a serie of jobs.
func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) { func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetJobs] batchSize=%d", batchSize)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetJobs] batchSize=%d", batchSize))
query := ` query := `
SELECT SELECT
id, user_id id, user_id
@ -29,7 +29,7 @@ func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) {
// NewUserBatch returns a serie of jobs but only for a given user. // NewUserBatch returns a serie of jobs but only for a given user.
func (s *Storage) NewUserBatch(userID int64, batchSize int) (jobs model.JobList, err error) { func (s *Storage) NewUserBatch(userID int64, batchSize int) (jobs model.JobList, err error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetUserJobs] batchSize=%d, userID=%d", batchSize, userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetUserJobs] batchSize=%d, userID=%d", batchSize, userID))
query := ` query := `
SELECT SELECT
id, user_id id, user_id

View file

@ -8,15 +8,15 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
) )
// CreateSession creates a new session. // CreateSession creates a new session.
func (s *Storage) CreateSession() (*model.Session, error) { func (s *Storage) CreateSession() (*model.Session, error) {
session := model.Session{ session := model.Session{
ID: helper.GenerateRandomString(32), ID: crypto.GenerateRandomString(32),
Data: &model.SessionData{CSRF: helper.GenerateRandomString(64)}, Data: &model.SessionData{CSRF: crypto.GenerateRandomString(64)},
} }
query := "INSERT INTO sessions (id, data) VALUES ($1, $2)" query := "INSERT INTO sessions (id, data) VALUES ($1, $2)"

View file

@ -8,12 +8,12 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/timer"
) )
// Timezones returns all timezones supported by the database. // Timezones returns all timezones supported by the database.
func (s *Storage) Timezones() (map[string]string, error) { func (s *Storage) Timezones() (map[string]string, error) {
defer helper.ExecutionTime(time.Now(), "[Storage:Timezones]") defer timer.ExecutionTime(time.Now(), "[Storage:Timezones]")
timezones := make(map[string]string) timezones := make(map[string]string)
query := `select name from pg_timezone_names() order by name asc` query := `select name from pg_timezone_names() order by name asc`

View file

@ -13,15 +13,15 @@ import (
"github.com/lib/pq/hstore" "github.com/lib/pq/hstore"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
"github.com/miniflux/miniflux/timer"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
// SetLastLogin updates the last login date of a user. // SetLastLogin updates the last login date of a user.
func (s *Storage) SetLastLogin(userID int64) error { func (s *Storage) SetLastLogin(userID int64) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetLastLogin] userID=%d", userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetLastLogin] userID=%d", userID))
query := "UPDATE users SET last_login_at=now() WHERE id=$1" query := "UPDATE users SET last_login_at=now() WHERE id=$1"
_, err := s.db.Exec(query, userID) _, err := s.db.Exec(query, userID)
if err != nil { if err != nil {
@ -33,7 +33,7 @@ func (s *Storage) SetLastLogin(userID int64) error {
// UserExists checks if a user exists by using the given username. // UserExists checks if a user exists by using the given username.
func (s *Storage) UserExists(username string) bool { func (s *Storage) UserExists(username string) bool {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserExists] username=%s", username)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserExists] username=%s", username))
var result int var result int
s.db.QueryRow(`SELECT count(*) as c FROM users WHERE username=LOWER($1)`, username).Scan(&result) s.db.QueryRow(`SELECT count(*) as c FROM users WHERE username=LOWER($1)`, username).Scan(&result)
@ -42,7 +42,7 @@ func (s *Storage) UserExists(username string) bool {
// AnotherUserExists checks if another user exists with the given username. // AnotherUserExists checks if another user exists with the given username.
func (s *Storage) AnotherUserExists(userID int64, username string) bool { func (s *Storage) AnotherUserExists(userID int64, username string) bool {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherUserExists] userID=%d, username=%s", userID, username)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherUserExists] userID=%d, username=%s", userID, username))
var result int var result int
s.db.QueryRow(`SELECT count(*) as c FROM users WHERE id != $1 AND username=LOWER($2)`, userID, username).Scan(&result) s.db.QueryRow(`SELECT count(*) as c FROM users WHERE id != $1 AND username=LOWER($2)`, userID, username).Scan(&result)
@ -51,7 +51,7 @@ func (s *Storage) AnotherUserExists(userID int64, username string) bool {
// CreateUser creates a new user. // CreateUser creates a new user.
func (s *Storage) CreateUser(user *model.User) (err error) { func (s *Storage) CreateUser(user *model.User) (err error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateUser] username=%s", user.Username)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateUser] username=%s", user.Username))
password := "" password := ""
extra := hstore.Hstore{Map: make(map[string]sql.NullString)} extra := hstore.Hstore{Map: make(map[string]sql.NullString)}
@ -114,7 +114,7 @@ func (s *Storage) RemoveExtraField(userID int64, field string) error {
// UpdateUser updates a user. // UpdateUser updates a user.
func (s *Storage) UpdateUser(user *model.User) error { func (s *Storage) UpdateUser(user *model.User) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateUser] userID=%d", user.ID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateUser] userID=%d", user.ID))
if user.Password != "" { if user.Password != "" {
hashedPassword, err := hashPassword(user.Password) hashedPassword, err := hashPassword(user.Password)
@ -177,7 +177,7 @@ func (s *Storage) UpdateUser(user *model.User) error {
// UserByID finds a user by the ID. // UserByID finds a user by the ID.
func (s *Storage) UserByID(userID int64) (*model.User, error) { func (s *Storage) UserByID(userID int64) (*model.User, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByID] userID=%d", userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByID] userID=%d", userID))
query := `SELECT query := `SELECT
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
FROM users FROM users
@ -188,7 +188,7 @@ func (s *Storage) UserByID(userID int64) (*model.User, error) {
// UserByUsername finds a user by the username. // UserByUsername finds a user by the username.
func (s *Storage) UserByUsername(username string) (*model.User, error) { func (s *Storage) UserByUsername(username string) (*model.User, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByUsername] username=%s", username)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByUsername] username=%s", username))
query := `SELECT query := `SELECT
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
FROM users FROM users
@ -199,7 +199,7 @@ func (s *Storage) UserByUsername(username string) (*model.User, error) {
// UserByExtraField finds a user by an extra field value. // UserByExtraField finds a user by an extra field value.
func (s *Storage) UserByExtraField(field, value string) (*model.User, error) { func (s *Storage) UserByExtraField(field, value string) (*model.User, error) {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByExtraField] field=%s", field)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByExtraField] field=%s", field))
query := `SELECT query := `SELECT
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
FROM users FROM users
@ -241,7 +241,7 @@ func (s *Storage) fetchUser(query string, args ...interface{}) (*model.User, err
// RemoveUser deletes a user. // RemoveUser deletes a user.
func (s *Storage) RemoveUser(userID int64) error { func (s *Storage) RemoveUser(userID int64) error {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveUser] userID=%d", userID)) defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveUser] userID=%d", userID))
result, err := s.db.Exec("DELETE FROM users WHERE id = $1", userID) result, err := s.db.Exec("DELETE FROM users WHERE id = $1", userID)
if err != nil { if err != nil {
@ -262,7 +262,7 @@ func (s *Storage) RemoveUser(userID int64) error {
// Users returns all users. // Users returns all users.
func (s *Storage) Users() (model.Users, error) { func (s *Storage) Users() (model.Users, error) {
defer helper.ExecutionTime(time.Now(), "[Storage:Users]") defer timer.ExecutionTime(time.Now(), "[Storage:Users]")
query := ` query := `
SELECT SELECT
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
@ -309,7 +309,7 @@ func (s *Storage) Users() (model.Users, error) {
// CheckPassword validate the hashed password. // CheckPassword validate the hashed password.
func (s *Storage) CheckPassword(username, password string) error { func (s *Storage) CheckPassword(username, password string) error {
defer helper.ExecutionTime(time.Now(), "[Storage:CheckPassword]") defer timer.ExecutionTime(time.Now(), "[Storage:CheckPassword]")
var hash string var hash string
username = strings.ToLower(username) username = strings.ToLower(username)

View file

@ -8,7 +8,7 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/model" "github.com/miniflux/miniflux/model"
) )
@ -55,7 +55,7 @@ func (s *Storage) CreateUserSession(username, userAgent, ip string) (sessionID s
return "", fmt.Errorf("unable to fetch UserID: %v", err) return "", fmt.Errorf("unable to fetch UserID: %v", err)
} }
token := helper.GenerateRandomString(64) token := crypto.GenerateRandomString(64)
query := "INSERT INTO user_sessions (token, user_id, user_agent, ip) VALUES ($1, $2, $3, $4)" query := "INSERT INTO user_sessions (token, user_id, user_agent, ip) VALUES ($1, $2, $3, $4)"
_, err = s.db.Exec(query, token, userID, userAgent, ip) _, err = s.db.Exec(query, token, userID, userAgent, ip)
if err != nil { if err != nil {

View file

@ -1,8 +1,8 @@
// Copyright 2017 Frédéric Guillot. All rights reserved. // Copyright 2018 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0 // Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package helper package timer
import ( import (
"time" "time"