Browse Source

refactor(storage): unexport a bunch of symbols

jvoisin 2 months ago
parent
commit
9b859e7f3f

+ 11 - 11
internal/storage/batch.go

@@ -14,7 +14,7 @@ import (
 	"miniflux.app/v2/internal/urllib"
 )
 
-type BatchBuilder struct {
+type batchBuilder struct {
 	db           *sql.DB
 	args         []any
 	conditions   []string
@@ -22,30 +22,30 @@ type BatchBuilder struct {
 	limitPerHost int
 }
 
-func (s *Storage) NewBatchBuilder() *BatchBuilder {
-	return &BatchBuilder{
+func (s *Storage) NewBatchBuilder() *batchBuilder {
+	return &batchBuilder{
 		db: s.db,
 	}
 }
 
-func (b *BatchBuilder) WithBatchSize(batchSize int) *BatchBuilder {
+func (b *batchBuilder) WithBatchSize(batchSize int) *batchBuilder {
 	b.batchSize = batchSize
 	return b
 }
 
-func (b *BatchBuilder) WithUserID(userID int64) *BatchBuilder {
+func (b *batchBuilder) WithUserID(userID int64) *batchBuilder {
 	b.conditions = append(b.conditions, "user_id = $"+strconv.Itoa(len(b.args)+1))
 	b.args = append(b.args, userID)
 	return b
 }
 
-func (b *BatchBuilder) WithCategoryID(categoryID int64) *BatchBuilder {
+func (b *batchBuilder) WithCategoryID(categoryID int64) *batchBuilder {
 	b.conditions = append(b.conditions, "category_id = $"+strconv.Itoa(len(b.args)+1))
 	b.args = append(b.args, categoryID)
 	return b
 }
 
-func (b *BatchBuilder) WithErrorLimit(limit int) *BatchBuilder {
+func (b *batchBuilder) WithErrorLimit(limit int) *batchBuilder {
 	if limit > 0 {
 		b.conditions = append(b.conditions, "parsing_error_count < $"+strconv.Itoa(len(b.args)+1))
 		b.args = append(b.args, limit)
@@ -53,17 +53,17 @@ func (b *BatchBuilder) WithErrorLimit(limit int) *BatchBuilder {
 	return b
 }
 
-func (b *BatchBuilder) WithNextCheckExpired() *BatchBuilder {
+func (b *batchBuilder) WithNextCheckExpired() *batchBuilder {
 	b.conditions = append(b.conditions, "next_check_at < now()")
 	return b
 }
 
-func (b *BatchBuilder) WithoutDisabledFeeds() *BatchBuilder {
+func (b *batchBuilder) WithoutDisabledFeeds() *batchBuilder {
 	b.conditions = append(b.conditions, "disabled IS false")
 	return b
 }
 
-func (b *BatchBuilder) WithLimitPerHost(limit int) *BatchBuilder {
+func (b *batchBuilder) WithLimitPerHost(limit int) *batchBuilder {
 	if limit > 0 {
 		b.limitPerHost = limit
 	}
@@ -72,7 +72,7 @@ func (b *BatchBuilder) WithLimitPerHost(limit int) *BatchBuilder {
 
 // FetchJobs retrieves a batch of jobs based on the conditions set in the builder.
 // When limitPerHost is set, it limits the number of jobs per feed hostname to prevent overwhelming a single host.
-func (b *BatchBuilder) FetchJobs() (model.JobList, error) {
+func (b *batchBuilder) FetchJobs() (model.JobList, error) {
 	query := `SELECT id, user_id, feed_url FROM feeds`
 
 	if len(b.conditions) > 0 {

+ 8 - 8
internal/storage/certificate_cache.go

@@ -11,24 +11,24 @@ import (
 )
 
 // Making sure that we're adhering to the autocert.Cache interface.
-var _ autocert.Cache = (*CertificateCache)(nil)
+var _ autocert.Cache = (*certificateCache)(nil)
 
-// CertificateCache provides a SQL backend to the autocert cache.
-type CertificateCache struct {
+// certificateCache provides a SQL backend to the autocert cache.
+type certificateCache struct {
 	storage *Storage
 }
 
 // NewCertificateCache creates an cache instance that can be used with autocert.Cache.
 // It returns any errors that could happen while connecting to SQL.
-func NewCertificateCache(storage *Storage) *CertificateCache {
-	return &CertificateCache{
+func NewCertificateCache(storage *Storage) *certificateCache {
+	return &certificateCache{
 		storage: storage,
 	}
 }
 
 // Get returns a certificate data for the specified key.
 // If there's no such key, Get returns ErrCacheMiss.
-func (c *CertificateCache) Get(ctx context.Context, key string) ([]byte, error) {
+func (c *certificateCache) Get(ctx context.Context, key string) ([]byte, error) {
 	query := `SELECT data::bytea FROM acme_cache WHERE key = $1`
 	var data []byte
 	err := c.storage.db.QueryRowContext(ctx, query, key).Scan(&data)
@@ -40,7 +40,7 @@ func (c *CertificateCache) Get(ctx context.Context, key string) ([]byte, error)
 }
 
 // Put stores the data in the cache under the specified key.
-func (c *CertificateCache) Put(ctx context.Context, key string, data []byte) error {
+func (c *certificateCache) Put(ctx context.Context, key string, data []byte) error {
 	query := `INSERT INTO acme_cache (key, data, updated_at) VALUES($1, $2::bytea, now())
 	          ON CONFLICT (key) DO UPDATE SET data = $2::bytea, updated_at = now()`
 	_, err := c.storage.db.ExecContext(ctx, query, key, data)
@@ -52,7 +52,7 @@ func (c *CertificateCache) Put(ctx context.Context, key string, data []byte) err
 
 // Delete removes a certificate data from the cache under the specified key.
 // If there's no such key in the cache, Delete returns nil.
-func (c *CertificateCache) Delete(ctx context.Context, key string) error {
+func (c *certificateCache) Delete(ctx context.Context, key string) error {
 	query := `DELETE FROM acme_cache WHERE key = $1`
 	_, err := c.storage.db.ExecContext(ctx, query, key)
 	if err != nil {

+ 15 - 15
internal/storage/entry_pagination_builder.go

@@ -12,8 +12,8 @@ import (
 	"miniflux.app/v2/internal/model"
 )
 
-// EntryPaginationBuilder is a builder for entry prev/next queries.
-type EntryPaginationBuilder struct {
+// entryPaginationBuilder is a builder for entry prev/next queries.
+type entryPaginationBuilder struct {
 	store      *Storage
 	conditions []string
 	args       []any
@@ -23,7 +23,7 @@ type EntryPaginationBuilder struct {
 }
 
 // WithSearchQuery adds full-text search query to the condition.
-func (e *EntryPaginationBuilder) WithSearchQuery(query string) {
+func (e *entryPaginationBuilder) WithSearchQuery(query string) {
 	if query != "" {
 		e.conditions = append(e.conditions, fmt.Sprintf("e.document_vectors @@ plainto_tsquery($%d)", len(e.args)+1))
 		e.args = append(e.args, query)
@@ -31,12 +31,12 @@ func (e *EntryPaginationBuilder) WithSearchQuery(query string) {
 }
 
 // WithStarred adds starred to the condition.
-func (e *EntryPaginationBuilder) WithStarred() {
+func (e *entryPaginationBuilder) WithStarred() {
 	e.conditions = append(e.conditions, "e.starred is true")
 }
 
 // WithFeedID adds feed_id to the condition.
-func (e *EntryPaginationBuilder) WithFeedID(feedID int64) {
+func (e *entryPaginationBuilder) WithFeedID(feedID int64) {
 	if feedID != 0 {
 		e.conditions = append(e.conditions, "e.feed_id = $"+strconv.Itoa(len(e.args)+1))
 		e.args = append(e.args, feedID)
@@ -44,7 +44,7 @@ func (e *EntryPaginationBuilder) WithFeedID(feedID int64) {
 }
 
 // WithCategoryID adds category_id to the condition.
-func (e *EntryPaginationBuilder) WithCategoryID(categoryID int64) {
+func (e *entryPaginationBuilder) WithCategoryID(categoryID int64) {
 	if categoryID != 0 {
 		e.conditions = append(e.conditions, "f.category_id = $"+strconv.Itoa(len(e.args)+1))
 		e.args = append(e.args, categoryID)
@@ -52,7 +52,7 @@ func (e *EntryPaginationBuilder) WithCategoryID(categoryID int64) {
 }
 
 // WithStatus adds status to the condition.
-func (e *EntryPaginationBuilder) WithStatus(status string) {
+func (e *entryPaginationBuilder) WithStatus(status string) {
 	if status != "" {
 		e.conditions = append(e.conditions, "e.status = $"+strconv.Itoa(len(e.args)+1))
 		e.args = append(e.args, status)
@@ -60,7 +60,7 @@ func (e *EntryPaginationBuilder) WithStatus(status string) {
 }
 
 // WithStatusOrEntryID adds a status condition that always includes a specific entry ID.
-func (e *EntryPaginationBuilder) WithStatusOrEntryID(status string, entryID int64) {
+func (e *entryPaginationBuilder) WithStatusOrEntryID(status string, entryID int64) {
 	if status == "" {
 		return
 	}
@@ -76,7 +76,7 @@ func (e *EntryPaginationBuilder) WithStatusOrEntryID(status string, entryID int6
 	e.args = append(e.args, status, entryID)
 }
 
-func (e *EntryPaginationBuilder) WithTags(tags []string) {
+func (e *entryPaginationBuilder) WithTags(tags []string) {
 	if len(tags) > 0 {
 		for _, tag := range tags {
 			e.conditions = append(e.conditions, fmt.Sprintf("LOWER($%d) = ANY(LOWER(e.tags::text)::text[])", len(e.args)+1))
@@ -86,13 +86,13 @@ func (e *EntryPaginationBuilder) WithTags(tags []string) {
 }
 
 // WithGloballyVisible adds global visibility to the condition.
-func (e *EntryPaginationBuilder) WithGloballyVisible() {
+func (e *entryPaginationBuilder) WithGloballyVisible() {
 	e.conditions = append(e.conditions, "not c.hide_globally")
 	e.conditions = append(e.conditions, "not f.hide_globally")
 }
 
 // Entries returns previous and next entries.
-func (e *EntryPaginationBuilder) Entries() (*model.Entry, *model.Entry, error) {
+func (e *entryPaginationBuilder) Entries() (*model.Entry, *model.Entry, error) {
 	tx, err := e.store.db.Begin()
 	if err != nil {
 		return nil, nil, fmt.Errorf("begin transaction for entry pagination: %v", err)
@@ -125,7 +125,7 @@ func (e *EntryPaginationBuilder) Entries() (*model.Entry, *model.Entry, error) {
 	return prevEntry, nextEntry, nil
 }
 
-func (e *EntryPaginationBuilder) getPrevNextID(tx *sql.Tx) (prevID int64, nextID int64, err error) {
+func (e *entryPaginationBuilder) getPrevNextID(tx *sql.Tx) (prevID int64, nextID int64, err error) {
 	cte := `
 		WITH entry_pagination AS (
 			SELECT
@@ -166,7 +166,7 @@ func (e *EntryPaginationBuilder) getPrevNextID(tx *sql.Tx) (prevID int64, nextID
 	return prevID, nextID, nil
 }
 
-func (e *EntryPaginationBuilder) getEntry(tx *sql.Tx, entryID int64) (*model.Entry, error) {
+func (e *entryPaginationBuilder) getEntry(tx *sql.Tx, entryID int64) (*model.Entry, error) {
 	var entry model.Entry
 
 	err := tx.QueryRow(`SELECT id, title FROM entries WHERE id = $1`, entryID).Scan(
@@ -185,8 +185,8 @@ func (e *EntryPaginationBuilder) getEntry(tx *sql.Tx, entryID int64) (*model.Ent
 }
 
 // NewEntryPaginationBuilder returns a new EntryPaginationBuilder.
-func NewEntryPaginationBuilder(store *Storage, userID, entryID int64, order, direction string) *EntryPaginationBuilder {
-	return &EntryPaginationBuilder{
+func NewEntryPaginationBuilder(store *Storage, userID, entryID int64, order, direction string) *entryPaginationBuilder {
+	return &entryPaginationBuilder{
 		store:      store,
 		args:       []any{userID, "removed"},
 		conditions: []string{"e.user_id = $1", "e.status <> $2"},

+ 1 - 1
internal/storage/feed.go

@@ -148,7 +148,7 @@ func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
 	return builder.GetFeeds()
 }
 
-func getFeedsSorted(builder *FeedQueryBuilder) (model.Feeds, error) {
+func getFeedsSorted(builder *feedQueryBuilder) (model.Feeds, error) {
 	result, err := builder.GetFeeds()
 	if err == nil {
 		sort.Sort(byStateAndName{result})

+ 16 - 16
internal/storage/feed_query_builder.go

@@ -13,8 +13,8 @@ import (
 	"miniflux.app/v2/internal/timezone"
 )
 
-// FeedQueryBuilder builds a SQL query to fetch feeds.
-type FeedQueryBuilder struct {
+// feedQueryBuilder builds a SQL query to fetch feeds.
+type feedQueryBuilder struct {
 	store             *Storage
 	args              []any
 	conditions        []string
@@ -28,8 +28,8 @@ type FeedQueryBuilder struct {
 }
 
 // NewFeedQueryBuilder returns a new FeedQueryBuilder.
-func NewFeedQueryBuilder(store *Storage, userID int64) *FeedQueryBuilder {
-	return &FeedQueryBuilder{
+func NewFeedQueryBuilder(store *Storage, userID int64) *feedQueryBuilder {
+	return &feedQueryBuilder{
 		store:             store,
 		args:              []any{userID},
 		conditions:        []string{"f.user_id = $1"},
@@ -39,7 +39,7 @@ func NewFeedQueryBuilder(store *Storage, userID int64) *FeedQueryBuilder {
 }
 
 // WithCategoryID filter by category ID.
-func (f *FeedQueryBuilder) WithCategoryID(categoryID int64) *FeedQueryBuilder {
+func (f *feedQueryBuilder) WithCategoryID(categoryID int64) *feedQueryBuilder {
 	if categoryID > 0 {
 		f.conditions = append(f.conditions, "f.category_id = $"+strconv.Itoa(len(f.args)+1))
 		f.args = append(f.args, categoryID)
@@ -51,7 +51,7 @@ func (f *FeedQueryBuilder) WithCategoryID(categoryID int64) *FeedQueryBuilder {
 }
 
 // WithFeedID filter by feed ID.
-func (f *FeedQueryBuilder) WithFeedID(feedID int64) *FeedQueryBuilder {
+func (f *feedQueryBuilder) WithFeedID(feedID int64) *feedQueryBuilder {
 	if feedID > 0 {
 		f.conditions = append(f.conditions, "f.id = $"+strconv.Itoa(len(f.args)+1))
 		f.args = append(f.args, feedID)
@@ -60,38 +60,38 @@ func (f *FeedQueryBuilder) WithFeedID(feedID int64) *FeedQueryBuilder {
 }
 
 // WithCounters let the builder return feeds with counters of statuses of entries.
-func (f *FeedQueryBuilder) WithCounters() *FeedQueryBuilder {
+func (f *feedQueryBuilder) WithCounters() *feedQueryBuilder {
 	f.withCounters = true
 	return f
 }
 
 // WithSorting add a sort expression.
-func (f *FeedQueryBuilder) WithSorting(column, direction string) *FeedQueryBuilder {
+func (f *feedQueryBuilder) WithSorting(column, direction string) *feedQueryBuilder {
 	f.sortExpressions = append(f.sortExpressions, column+" "+direction)
 	return f
 }
 
 // WithLimit set the limit.
-func (f *FeedQueryBuilder) WithLimit(limit int) *FeedQueryBuilder {
+func (f *feedQueryBuilder) WithLimit(limit int) *feedQueryBuilder {
 	f.limit = limit
 	return f
 }
 
 // WithOffset set the offset.
-func (f *FeedQueryBuilder) WithOffset(offset int) *FeedQueryBuilder {
+func (f *feedQueryBuilder) WithOffset(offset int) *feedQueryBuilder {
 	f.offset = offset
 	return f
 }
 
-func (f *FeedQueryBuilder) buildCondition() string {
+func (f *feedQueryBuilder) buildCondition() string {
 	return strings.Join(f.conditions, " AND ")
 }
 
-func (f *FeedQueryBuilder) buildCounterCondition() string {
+func (f *feedQueryBuilder) buildCounterCondition() string {
 	return strings.Join(f.counterConditions, " AND ")
 }
 
-func (f *FeedQueryBuilder) buildSorting() string {
+func (f *feedQueryBuilder) buildSorting() string {
 	var parts string
 
 	if len(f.sortExpressions) > 0 {
@@ -114,7 +114,7 @@ func (f *FeedQueryBuilder) buildSorting() string {
 }
 
 // GetFeed returns a single feed that match the condition.
-func (f *FeedQueryBuilder) GetFeed() (*model.Feed, error) {
+func (f *feedQueryBuilder) GetFeed() (*model.Feed, error) {
 	f.limit = 1
 	feeds, err := f.GetFeeds()
 	if err != nil {
@@ -129,7 +129,7 @@ func (f *FeedQueryBuilder) GetFeed() (*model.Feed, error) {
 }
 
 // GetFeeds returns a list of feeds that match the condition.
-func (f *FeedQueryBuilder) GetFeeds() (model.Feeds, error) {
+func (f *feedQueryBuilder) GetFeeds() (model.Feeds, error) {
 	var query = `
 		SELECT
 			f.id,
@@ -291,7 +291,7 @@ func (f *FeedQueryBuilder) GetFeeds() (model.Feeds, error) {
 	return feeds, nil
 }
 
-func (f *FeedQueryBuilder) fetchFeedCounter() (unreadCounters map[int64]int, readCounters map[int64]int, err error) {
+func (f *feedQueryBuilder) fetchFeedCounter() (unreadCounters map[int64]int, readCounters map[int64]int, err error) {
 	if !f.withCounters {
 		return nil, nil, nil
 	}