diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-01-02 19:15:08 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-01-02 19:15:08 -0800 |
commit | c39f2e1a8d2de6d412bcc673d29eb0f7a2d1f5f7 (patch) | |
tree | 950efc2155037ce055e1aae334e160812b0ee38f /storage | |
parent | 3c3f397bf57e232201fccd64bad2820e6ade567a (diff) |
Rename helper packages
Diffstat (limited to 'storage')
-rw-r--r-- | storage/category.go | 22 | ||||
-rw-r--r-- | storage/entry.go | 8 | ||||
-rw-r--r-- | storage/entry_query_builder.go | 8 | ||||
-rw-r--r-- | storage/feed.go | 16 | ||||
-rw-r--r-- | storage/icon.go | 14 | ||||
-rw-r--r-- | storage/job.go | 6 | ||||
-rw-r--r-- | storage/session.go | 6 | ||||
-rw-r--r-- | storage/timezone.go | 4 | ||||
-rw-r--r-- | storage/user.go | 24 | ||||
-rw-r--r-- | storage/user_session.go | 4 |
10 files changed, 56 insertions, 56 deletions
diff --git a/storage/category.go b/storage/category.go index a9de759..197b78b 100644 --- a/storage/category.go +++ b/storage/category.go @@ -10,13 +10,13 @@ import ( "fmt" "time" - "github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/model" + "github.com/miniflux/miniflux/timer" ) // AnotherCategoryExists checks if another category exists with the same title. 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 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. 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 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. 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 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. 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 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. 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 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. 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` 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. 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 c.id, c.user_id, c.title, (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. 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 := ` INSERT INTO categories @@ -159,7 +159,7 @@ func (s *Storage) CreateCategory(category *model.Category) error { // UpdateCategory updates an existing category. 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` _, err := s.db.Exec( @@ -178,7 +178,7 @@ func (s *Storage) UpdateCategory(category *model.Category) error { // RemoveCategory deletes a category. 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) if err != nil { diff --git a/storage/entry.go b/storage/entry.go index 176dcde..3be6c92 100644 --- a/storage/entry.go +++ b/storage/entry.go @@ -9,9 +9,9 @@ import ( "fmt" "time" - "github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/logger" "github.com/miniflux/miniflux/model" + "github.com/miniflux/miniflux/timer" "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. 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)` 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. 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` 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". 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'` _, err := s.db.Exec(query, model.EntryStatusRemoved, userID, model.EntryStatusRead) diff --git a/storage/entry_query_builder.go b/storage/entry_query_builder.go index 99fa4e5..7c8d924 100644 --- a/storage/entry_query_builder.go +++ b/storage/entry_query_builder.go @@ -11,8 +11,8 @@ import ( "github.com/lib/pq" - "github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/model" + "github.com/miniflux/miniflux/timer" ) // 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. func (e *EntryQueryBuilder) CountEntries() (count int, err error) { - defer helper.ExecutionTime( + defer timer.ExecutionTime( time.Now(), 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. 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" - 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 := ` SELECT @@ -233,7 +233,7 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { // GetEntryIDs returns a list of entry IDs that match the condition. 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" - 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 := ` SELECT diff --git a/storage/feed.go b/storage/feed.go index ae6d50a..87b234a 100644 --- a/storage/feed.go +++ b/storage/feed.go @@ -10,13 +10,13 @@ import ( "fmt" "time" - "github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/model" + "github.com/miniflux/miniflux/timer" ) // FeedExists checks if the given feed exists. 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 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. 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 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. 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) query := `SELECT @@ -110,7 +110,7 @@ func (s *Storage) Feeds(userID int64) (model.Feeds, error) { // FeedByID returns a feed by the ID. 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 iconID interface{} @@ -165,7 +165,7 @@ func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) { // CreateFeed creates a new feed. 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 := ` INSERT INTO feeds (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. 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 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. 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) if err != nil { diff --git a/storage/icon.go b/storage/icon.go index f5c71cb..5e8b5dc 100644 --- a/storage/icon.go +++ b/storage/icon.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/model" + "github.com/miniflux/miniflux/timer" ) // 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. 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 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. 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 := ` SELECT 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). 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) if err == sql.ErrNoRows { @@ -76,7 +76,7 @@ func (s *Storage) IconByHash(icon *model.Icon) error { // CreateIcon creates a new icon. func (s *Storage) CreateIcon(icon *model.Icon) error { - defer helper.ExecutionTime(time.Now(), "[Storage:CreateIcon]") + defer timer.ExecutionTime(time.Now(), "[Storage:CreateIcon]") query := ` 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. 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) 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. 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 := ` SELECT icons.id, icons.hash, icons.mime_type, icons.content diff --git a/storage/job.go b/storage/job.go index f8b11d8..20a0efa 100644 --- a/storage/job.go +++ b/storage/job.go @@ -8,15 +8,15 @@ import ( "fmt" "time" - "github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/model" + "github.com/miniflux/miniflux/timer" ) const maxParsingError = 3 // NewBatch returns a serie of jobs. 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 := ` SELECT 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. 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 := ` SELECT id, user_id diff --git a/storage/session.go b/storage/session.go index 106d618..1e6fb42 100644 --- a/storage/session.go +++ b/storage/session.go @@ -8,15 +8,15 @@ import ( "database/sql" "fmt" - "github.com/miniflux/miniflux/helper" + "github.com/miniflux/miniflux/crypto" "github.com/miniflux/miniflux/model" ) // CreateSession creates a new session. func (s *Storage) CreateSession() (*model.Session, error) { session := model.Session{ - ID: helper.GenerateRandomString(32), - Data: &model.SessionData{CSRF: helper.GenerateRandomString(64)}, + ID: crypto.GenerateRandomString(32), + Data: &model.SessionData{CSRF: crypto.GenerateRandomString(64)}, } query := "INSERT INTO sessions (id, data) VALUES ($1, $2)" diff --git a/storage/timezone.go b/storage/timezone.go index 72dbb1d..949a6af 100644 --- a/storage/timezone.go +++ b/storage/timezone.go @@ -8,12 +8,12 @@ import ( "fmt" "time" - "github.com/miniflux/miniflux/helper" + "github.com/miniflux/miniflux/timer" ) // Timezones returns all timezones supported by the database. 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) query := `select name from pg_timezone_names() order by name asc` diff --git a/storage/user.go b/storage/user.go index 31aadf0..5d64b65 100644 --- a/storage/user.go +++ b/storage/user.go @@ -13,15 +13,15 @@ import ( "github.com/lib/pq/hstore" - "github.com/miniflux/miniflux/helper" "github.com/miniflux/miniflux/model" + "github.com/miniflux/miniflux/timer" "golang.org/x/crypto/bcrypt" ) // SetLastLogin updates the last login date of a user. 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" _, err := s.db.Exec(query, userID) 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. 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 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. 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 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. 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 := "" 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. 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 != "" { hashedPassword, err := hashPassword(user.Password) @@ -177,7 +177,7 @@ func (s *Storage) UpdateUser(user *model.User) error { // UserByID finds a user by the ID. 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 id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra FROM users @@ -188,7 +188,7 @@ func (s *Storage) UserByID(userID int64) (*model.User, error) { // UserByUsername finds a user by the username. 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 id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra FROM users @@ -199,7 +199,7 @@ func (s *Storage) UserByUsername(username string) (*model.User, error) { // UserByExtraField finds a user by an extra field value. 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 id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra FROM users @@ -241,7 +241,7 @@ func (s *Storage) fetchUser(query string, args ...interface{}) (*model.User, err // RemoveUser deletes a user. 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) if err != nil { @@ -262,7 +262,7 @@ func (s *Storage) RemoveUser(userID int64) error { // Users returns all users. func (s *Storage) Users() (model.Users, error) { - defer helper.ExecutionTime(time.Now(), "[Storage:Users]") + defer timer.ExecutionTime(time.Now(), "[Storage:Users]") query := ` SELECT 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. 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 username = strings.ToLower(username) diff --git a/storage/user_session.go b/storage/user_session.go index 9a87cdf..3649f42 100644 --- a/storage/user_session.go +++ b/storage/user_session.go @@ -8,7 +8,7 @@ import ( "database/sql" "fmt" - "github.com/miniflux/miniflux/helper" + "github.com/miniflux/miniflux/crypto" "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) } - token := helper.GenerateRandomString(64) + token := crypto.GenerateRandomString(64) 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) if err != nil { |