mirror of
https://github.com/miniflux/v2.git
synced 2025-08-16 18:01:37 +00:00
refactor(model): remove some indirection
For small fixed-size structures, it's better to use a slice of values, instead of a slice of pointers to values: they're stored contiguously and thus can be iterated on quickly by the CPU, and it does remove an indirection per object every time the GC kicks in.
This commit is contained in:
parent
1e6d227e40
commit
8bca777a6d
6 changed files with 12 additions and 9 deletions
|
@ -8,6 +8,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// APIKey represents an application API key.
|
// APIKey represents an application API key.
|
||||||
|
// We need to use a pointer for LastUsedAt,
|
||||||
|
// as the value obtained from the database might sometimes be nil.
|
||||||
type APIKey struct {
|
type APIKey struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
UserID int64 `json:"user_id"`
|
UserID int64 `json:"user_id"`
|
||||||
|
@ -18,7 +20,7 @@ type APIKey struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// APIKeys represents a collection of API Key.
|
// APIKeys represents a collection of API Key.
|
||||||
type APIKeys []*APIKey
|
type APIKeys []APIKey
|
||||||
|
|
||||||
// APIKeyCreationRequest represents the request to create a new API Key.
|
// APIKeyCreationRequest represents the request to create a new API Key.
|
||||||
type APIKeyCreationRequest struct {
|
type APIKeyCreationRequest struct {
|
||||||
|
|
|
@ -11,6 +11,7 @@ type Category struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
UserID int64 `json:"user_id"`
|
UserID int64 `json:"user_id"`
|
||||||
HideGlobally bool `json:"hide_globally"`
|
HideGlobally bool `json:"hide_globally"`
|
||||||
|
// Pointers are needed to avoid breaking /v1/categories?counts=true
|
||||||
FeedCount *int `json:"feed_count,omitempty"`
|
FeedCount *int `json:"feed_count,omitempty"`
|
||||||
TotalUnread *int `json:"total_unread,omitempty"`
|
TotalUnread *int `json:"total_unread,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -40,4 +41,4 @@ func (c *CategoryModificationRequest) Patch(category *Category) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Categories represents a list of categories.
|
// Categories represents a list of categories.
|
||||||
type Categories []*Category
|
type Categories []Category
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (u *UserSession) UseTimezone(tz string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserSessions represents a list of sessions.
|
// UserSessions represents a list of sessions.
|
||||||
type UserSessions []*UserSession
|
type UserSessions []UserSession
|
||||||
|
|
||||||
// UseTimezone converts creation date of all sessions to the given timezone.
|
// UseTimezone converts creation date of all sessions to the given timezone.
|
||||||
func (u UserSessions) UseTimezone(tz string) {
|
func (u UserSessions) UseTimezone(tz string) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ func (s *Storage) APIKeys(userID int64) (model.APIKeys, error) {
|
||||||
return nil, fmt.Errorf(`store: unable to fetch API Key row: %v`, err)
|
return nil, fmt.Errorf(`store: unable to fetch API Key row: %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
apiKeys = append(apiKeys, &apiKey)
|
apiKeys = append(apiKeys, apiKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiKeys, nil
|
return apiKeys, nil
|
||||||
|
|
|
@ -103,7 +103,7 @@ func (s *Storage) Categories(userID int64) (model.Categories, error) {
|
||||||
return nil, fmt.Errorf(`store: unable to fetch category row: %v`, err)
|
return nil, fmt.Errorf(`store: unable to fetch category row: %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
categories = append(categories, &category)
|
categories = append(categories, category)
|
||||||
}
|
}
|
||||||
|
|
||||||
return categories, nil
|
return categories, nil
|
||||||
|
@ -158,7 +158,7 @@ func (s *Storage) CategoriesWithFeedCount(userID int64) (model.Categories, error
|
||||||
return nil, fmt.Errorf(`store: unable to fetch category row: %v`, err)
|
return nil, fmt.Errorf(`store: unable to fetch category row: %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
categories = append(categories, &category)
|
categories = append(categories, category)
|
||||||
}
|
}
|
||||||
|
|
||||||
return categories, nil
|
return categories, nil
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (s *Storage) UserSessions(userID int64) (model.UserSessions, error) {
|
||||||
return nil, fmt.Errorf(`store: unable to fetch user session row: %v`, err)
|
return nil, fmt.Errorf(`store: unable to fetch user session row: %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sessions = append(sessions, &session)
|
sessions = append(sessions, session)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessions, nil
|
return sessions, nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue