From 0dff43233791ae7949ea6f9a50326bbb3f3769e5 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 28 Apr 2019 20:13:34 -0700 Subject: Remove debug timer from most storage functions --- storage/category.go | 18 ------------------ storage/entry.go | 13 ------------- storage/feed.go | 17 ----------------- storage/icon.go | 12 ------------ storage/job.go | 5 ----- storage/timezone.go | 4 ---- storage/user.go | 19 ------------------- 7 files changed, 88 deletions(-) (limited to 'storage') diff --git a/storage/category.go b/storage/category.go index deb8e24..72ba24b 100644 --- a/storage/category.go +++ b/storage/category.go @@ -8,16 +8,12 @@ import ( "database/sql" "errors" "fmt" - "time" "miniflux.app/model" - "miniflux.app/timer" ) // AnotherCategoryExists checks if another category exists with the same title. func (s *Storage) AnotherCategoryExists(userID, categoryID int64, title string) bool { - 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` s.db.QueryRow(query, userID, categoryID, title).Scan(&result) @@ -26,8 +22,6 @@ 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 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` s.db.QueryRow(query, userID, categoryID).Scan(&result) @@ -36,7 +30,6 @@ 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 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 +45,6 @@ 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 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 +60,6 @@ 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 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,8 +75,6 @@ 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 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) if err != nil { @@ -108,7 +97,6 @@ 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 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 @@ -136,8 +124,6 @@ func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error // CreateCategory creates a new category. func (s *Storage) CreateCategory(category *model.Category) error { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateCategory] title=%s", category.Title)) - query := ` INSERT INTO categories (user_id, title) @@ -160,8 +146,6 @@ func (s *Storage) CreateCategory(category *model.Category) error { // UpdateCategory updates an existing category. func (s *Storage) UpdateCategory(category *model.Category) error { - 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( query, @@ -179,8 +163,6 @@ func (s *Storage) UpdateCategory(category *model.Category) error { // RemoveCategory deletes a category. func (s *Storage) RemoveCategory(userID, categoryID int64) error { - 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 { return fmt.Errorf("Unable to remove this category: %v", err) diff --git a/storage/entry.go b/storage/entry.go index e32ac14..d3d16bb 100644 --- a/storage/entry.go +++ b/storage/entry.go @@ -11,7 +11,6 @@ import ( "miniflux.app/logger" "miniflux.app/model" - "miniflux.app/timer" "github.com/lib/pq" ) @@ -204,8 +203,6 @@ func (s *Storage) ArchiveEntries(days int) error { // SetEntriesStatus update the status of the given list of entries. func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string) error { - 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)) if err != nil { @@ -226,8 +223,6 @@ 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 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) if err != nil { @@ -248,8 +243,6 @@ 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 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) if err != nil { @@ -261,8 +254,6 @@ func (s *Storage) FlushHistory(userID int64) error { // MarkAllAsRead updates all user entries to the read status. func (s *Storage) MarkAllAsRead(userID int64) error { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:MarkAllAsRead] userID=%d", userID)) - query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND status=$3` result, err := s.db.Exec(query, model.EntryStatusRead, userID, model.EntryStatusUnread) if err != nil { @@ -277,8 +268,6 @@ func (s *Storage) MarkAllAsRead(userID int64) error { // MarkFeedAsRead updates all feed entries to the read status. func (s *Storage) MarkFeedAsRead(userID, feedID int64, before time.Time) error { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:MarkFeedAsRead] userID=%d, feedID=%d, before=%v", userID, feedID, before)) - query := ` UPDATE entries SET status=$1 @@ -298,8 +287,6 @@ func (s *Storage) MarkFeedAsRead(userID, feedID int64, before time.Time) error { // MarkCategoryAsRead updates all category entries to the read status. func (s *Storage) MarkCategoryAsRead(userID, categoryID int64, before time.Time) error { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:MarkCategoryAsRead] userID=%d, categoryID=%d, before=%v", userID, categoryID, before)) - query := ` UPDATE entries SET status=$1 diff --git a/storage/feed.go b/storage/feed.go index 6d0684e..5c2df83 100644 --- a/storage/feed.go +++ b/storage/feed.go @@ -8,17 +8,13 @@ import ( "database/sql" "errors" "fmt" - "time" "miniflux.app/model" - "miniflux.app/timer" "miniflux.app/timezone" ) // FeedExists checks if the given feed exists. func (s *Storage) FeedExists(userID, feedID int64) bool { - 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` s.db.QueryRow(query, userID, feedID).Scan(&result) @@ -27,8 +23,6 @@ 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 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` s.db.QueryRow(query, userID, feedURL).Scan(&result) @@ -59,8 +53,6 @@ func (s *Storage) CountErrorFeeds(userID int64) int { // Feeds returns all feeds of the given user. func (s *Storage) Feeds(userID int64) (model.Feeds, error) { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:Feeds] userID=%d", userID)) - feeds := make(model.Feeds, 0) query := `SELECT f.id, f.feed_url, f.site_url, f.title, f.etag_header, f.last_modified_header, @@ -130,8 +122,6 @@ 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 timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:FeedByID] feedID=%d", feedID)) - var feed model.Feed var iconID interface{} var tz string @@ -193,7 +183,6 @@ func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) { // CreateFeed creates a new feed. func (s *Storage) CreateFeed(feed *model.Feed) error { - 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, user_agent, username, password) @@ -233,8 +222,6 @@ func (s *Storage) CreateFeed(feed *model.Feed) error { // UpdateFeed updates an existing feed. func (s *Storage) UpdateFeed(feed *model.Feed) (err error) { - 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, parsing_error_msg=$8, parsing_error_count=$9, scraper_rules=$10, rewrite_rules=$11, crawler=$12, user_agent=$13, @@ -270,8 +257,6 @@ func (s *Storage) UpdateFeed(feed *model.Feed) (err error) { // UpdateFeedError updates feed errors. func (s *Storage) UpdateFeedError(feed *model.Feed) (err error) { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateFeedError] feedID=%d", feed.ID)) - query := ` UPDATE feeds SET @@ -297,8 +282,6 @@ func (s *Storage) UpdateFeedError(feed *model.Feed) (err error) { // RemoveFeed removes a feed. func (s *Storage) RemoveFeed(userID, feedID int64) error { - 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 { return fmt.Errorf("unable to remove feed #%d: %v", feedID, err) diff --git a/storage/icon.go b/storage/icon.go index aa9f99e..7ad7d06 100644 --- a/storage/icon.go +++ b/storage/icon.go @@ -8,10 +8,8 @@ import ( "database/sql" "fmt" "strings" - "time" "miniflux.app/model" - "miniflux.app/timer" ) // HasIcon checks if the given feed has an icon. @@ -24,8 +22,6 @@ func (s *Storage) HasIcon(feedID int64) bool { // IconByID returns an icon by the ID. func (s *Storage) IconByID(iconID int64) (*model.Icon, error) { - defer timer.ExecutionTime(time.Now(), "[Storage:IconByID]") - var icon model.Icon query := `SELECT id, hash, mime_type, content FROM icons WHERE id=$1` err := s.db.QueryRow(query, iconID).Scan(&icon.ID, &icon.Hash, &icon.MimeType, &icon.Content) @@ -40,7 +36,6 @@ 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 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,8 +57,6 @@ 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 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 { return nil @@ -76,8 +69,6 @@ func (s *Storage) IconByHash(icon *model.Icon) error { // CreateIcon creates a new icon. func (s *Storage) CreateIcon(icon *model.Icon) error { - defer timer.ExecutionTime(time.Now(), "[Storage:CreateIcon]") - query := ` INSERT INTO icons (hash, mime_type, content) @@ -101,8 +92,6 @@ func (s *Storage) CreateIcon(icon *model.Icon) error { // CreateFeedIcon creates an icon and associate the icon to the given feed. func (s *Storage) CreateFeedIcon(feedID int64, icon *model.Icon) error { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateFeedIcon] feedID=%d", feedID)) - err := s.IconByHash(icon) if err != nil { return err @@ -125,7 +114,6 @@ func (s *Storage) CreateFeedIcon(feedID int64, icon *model.Icon) error { // Icons returns all icons tht belongs to a user. func (s *Storage) Icons(userID int64) (model.Icons, error) { - 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 41e63fa..e115533 100644 --- a/storage/job.go +++ b/storage/job.go @@ -6,17 +6,14 @@ package storage // import "miniflux.app/storage" import ( "fmt" - "time" "miniflux.app/model" - "miniflux.app/timer" ) const maxParsingError = 3 // NewBatch returns a serie of jobs. func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetJobs] batchSize=%d", batchSize)) query := ` SELECT id, user_id @@ -29,8 +26,6 @@ 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 timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetUserJobs] batchSize=%d, userID=%d", batchSize, userID)) - // We do not take the error counter into consideration when the given // user refresh manually all his feeds to force a refresh. query := ` diff --git a/storage/timezone.go b/storage/timezone.go index 714d003..e5174ca 100644 --- a/storage/timezone.go +++ b/storage/timezone.go @@ -7,14 +7,10 @@ package storage // import "miniflux.app/storage" import ( "fmt" "strings" - "time" - - "miniflux.app/timer" ) // Timezones returns all timezones supported by the database. func (s *Storage) Timezones() (map[string]string, error) { - defer timer.ExecutionTime(time.Now(), "[Storage:Timezones]") timezones := make(map[string]string) rows, err := s.db.Query(`SELECT name FROM pg_timezone_names() ORDER BY name ASC`) if err != nil { diff --git a/storage/user.go b/storage/user.go index 9e236f7..cd85f8d 100644 --- a/storage/user.go +++ b/storage/user.go @@ -9,10 +9,8 @@ import ( "errors" "fmt" "strings" - "time" "miniflux.app/model" - "miniflux.app/timer" "github.com/lib/pq/hstore" "golang.org/x/crypto/bcrypt" @@ -20,7 +18,6 @@ import ( // SetLastLogin updates the last login date of a user. func (s *Storage) SetLastLogin(userID int64) error { - 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 { @@ -32,8 +29,6 @@ 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 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) return result >= 1 @@ -41,8 +36,6 @@ 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 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) return result >= 1 @@ -50,7 +43,6 @@ func (s *Storage) AnotherUserExists(userID int64, username string) bool { // CreateUser creates a new user. func (s *Storage) CreateUser(user *model.User) (err error) { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateUser] username=%s", user.Username)) password := "" extra := hstore.Hstore{Map: make(map[string]sql.NullString)} @@ -117,8 +109,6 @@ func (s *Storage) RemoveExtraField(userID int64, field string) error { // UpdateUser updates a user. func (s *Storage) UpdateUser(user *model.User) error { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateUser] userID=%d", user.ID)) - if user.Password != "" { hashedPassword, err := hashPassword(user.Password) if err != nil { @@ -190,7 +180,6 @@ func (s *Storage) UpdateUser(user *model.User) error { // UserLanguage returns the language of the given user. func (s *Storage) UserLanguage(userID int64) (language string) { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserLanguage] userID=%d", userID)) err := s.db.QueryRow(`SELECT language FROM users WHERE id = $1`, userID).Scan(&language) if err != nil { return "en_US" @@ -201,7 +190,6 @@ func (s *Storage) UserLanguage(userID int64) (language string) { // UserByID finds a user by the ID. func (s *Storage) UserByID(userID int64) (*model.User, error) { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByID] userID=%d", userID)) query := ` SELECT id, username, is_admin, theme, language, timezone, entry_direction, keyboard_shortcuts, @@ -217,7 +205,6 @@ 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 timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByUsername] username=%s", username)) query := ` SELECT id, username, is_admin, theme, language, timezone, entry_direction, keyboard_shortcuts, @@ -233,7 +220,6 @@ 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 timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByExtraField] field=%s", field)) query := ` SELECT id, username, is_admin, theme, language, timezone, entry_direction, keyboard_shortcuts, @@ -281,8 +267,6 @@ func (s *Storage) fetchUser(query string, args ...interface{}) (*model.User, err // RemoveUser deletes a user. func (s *Storage) RemoveUser(userID int64) error { - 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 { return fmt.Errorf("unable to remove this user: %v", err) @@ -302,7 +286,6 @@ func (s *Storage) RemoveUser(userID int64) error { // Users returns all users. func (s *Storage) Users() (model.Users, error) { - defer timer.ExecutionTime(time.Now(), "[Storage:Users]") query := ` SELECT id, username, is_admin, theme, language, timezone, entry_direction, keyboard_shortcuts, @@ -353,8 +336,6 @@ func (s *Storage) Users() (model.Users, error) { // CheckPassword validate the hashed password. func (s *Storage) CheckPassword(username, password string) error { - defer timer.ExecutionTime(time.Now(), "[Storage:CheckPassword]") - var hash string username = strings.ToLower(username) -- cgit v1.2.3