storage

package
v0.0.0-...-d07f01d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2026 License: Unlicense Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Abonnement

type Abonnement struct {
	Feed
	Chats []Chat
}

type AbonnementStorage

type AbonnementStorage interface {
	Create(chatId int64, chatTitle string, feedUrl string, lastEntry, etag, lastModified *string, hints PollHints, nextPollAt time.Time) error
	Delete(chatId int64, feedId int64) error
	ExistsByFeedUrl(chatId int64, feedUrl string) (bool, error)
	ExistsById(chatId int64, feedId int64) (bool, error)
	GetByUser(chatId int64) ([]Feed, error)
	GetAll() ([]Abonnement, error)
	GetDue() ([]Abonnement, error)
	SetFeedState(feedID int64, lastEntry, etag, lastModified *string, hints PollHints, nextPollAt time.Time, errorCount, unchangedCount int) error
	Reschedule(feedID int64, nextPollAt time.Time, errorCount, unchangedCount int) error
	MoveFeedURL(feedID int64, newURL string) (bool, error)
	DisableFeed(feedID int64, reason string) error
	ReactivateFeed(feedUrl string, nextPollAt time.Time) (bool, error)
}

type Abonnements

type Abonnements struct {
	*sqlx.DB
}

func (*Abonnements) Create

func (db *Abonnements) Create(chatId int64, chatTitle string, feedUrl string, lastEntry, etag, lastModified *string, hints PollHints, nextPollAt time.Time) error

func (*Abonnements) Delete

func (db *Abonnements) Delete(chatId int64, feedId int64) error

func (*Abonnements) DisableFeed

func (db *Abonnements) DisableFeed(feedID int64, reason string) error

DisableFeed retires a feed that has gone away (FRB110-118).

func (*Abonnements) ExistsByFeedUrl

func (db *Abonnements) ExistsByFeedUrl(chatId int64, feedUrl string) (bool, error)

func (*Abonnements) ExistsById

func (db *Abonnements) ExistsById(chatId int64, feedId int64) (bool, error)

func (*Abonnements) GetAll

func (db *Abonnements) GetAll() ([]Abonnement, error)

func (*Abonnements) GetByUser

func (db *Abonnements) GetByUser(chatId int64) ([]Feed, error)

func (*Abonnements) GetDue

func (db *Abonnements) GetDue() ([]Abonnement, error)

GetDue returns only feeds that are enabled and whose scheduled poll time has passed (or was never set). This is what keeps polling on a per-feed schedule and prevents a process restart from re-downloading everything (FRB037). Timestamps are always passed from Go instead of using NOW(), so they are written and compared in the driver's loc regardless of the MySQL time zone.

func (*Abonnements) MoveFeedURL

func (db *Abonnements) MoveFeedURL(feedID int64, newURL string) (bool, error)

MoveFeedURL persists a permanent redirect target (FRB130/131). If another feed already occupies newURL (feeds.url is UNIQUE), this feed's subscriptions are merged onto that existing feed instead and the old feed row is removed; the returned bool reports whether such a merge happened.

func (*Abonnements) ReactivateFeed

func (db *Abonnements) ReactivateFeed(feedUrl string, nextPollAt time.Time) (bool, error)

ReactivateFeed re-enables a retired feed, e.g. after it was successfully fetched again on subscribe. It reports whether the feed was disabled.

func (*Abonnements) Reschedule

func (db *Abonnements) Reschedule(feedID int64, nextPollAt time.Time, errorCount, unchangedCount int) error

Reschedule updates only the poll schedule and counters, preserving the cached etag/last_modified (FRB010-016) — used for 304, rate-limiting and transient errors. failing_since marks the start of an error streak and is cleared once errorCount drops back to 0.

func (*Abonnements) SetFeedState

func (db *Abonnements) SetFeedState(feedID int64, lastEntry, etag, lastModified *string, hints PollHints, nextPollAt time.Time, errorCount, unchangedCount int) error

SetFeedState writes the atomic cache set (etag + last_modified), the last seen entry, the feed's polling hints and the next poll schedule after a successful 200 response.

type Chat

type Chat struct {
	ID        int64     `db:"chat_id"`
	Title     string    `db:"title"`
	CreatedAt time.Time `db:"chat_created_at"`
}

type DB

type DB struct {
	*sqlx.DB
	Abonnements  AbonnementStorage
	Replacements ReplacementsStorage
}

func Connect

func Connect() (*DB, error)

func (*DB) Migrate

func (db *DB) Migrate() (int, error)

type Feed

type Feed struct {
	ID             int64          `db:"id"`
	Url            string         `db:"url"`
	LastEntry      sql.NullString `db:"last_entry"`
	CreatedAt      time.Time      `db:"created_at"`
	UpdatedAt      sql.NullTime   `db:"updated_at"`
	ETag           sql.NullString `db:"etag"`
	LastModified   sql.NullString `db:"last_modified"`
	NextPollAt     sql.NullTime   `db:"next_poll_at"`
	LastPollAt     sql.NullTime   `db:"last_poll_at"`
	ErrorCount     int            `db:"error_count"`
	UnchangedCount int            `db:"unchanged_count"`
	Disabled       bool           `db:"disabled"`
	DisabledReason sql.NullString `db:"disabled_reason"`
	FeedInterval   int            `db:"feed_interval"`
	SkipHours      sql.NullString `db:"skip_hours"`
	SkipDays       sql.NullString `db:"skip_days"`
	FailingSince   sql.NullTime   `db:"failing_since"`
}

func (Feed) Hints

func (f Feed) Hints() PollHints

Hints decodes the persisted polling hints of a feed.

type PollHints

type PollHints struct {
	Interval  time.Duration
	SkipHours []int
	SkipDays  []string
}

PollHints are the polling hints a feed declares in its body (ttl, skipHours, skipDays). They are persisted so they still apply after a 304.

type Replacement

type Replacement struct {
	ID        int64     `db:"id"`
	Value     string    `db:"value"`
	IsRegex   bool      `db:"is_regex"`
	CreatedAt time.Time `db:"created_at"`
}

type Replacements

type Replacements struct {
	*sqlx.DB
}

func (*Replacements) Create

func (db *Replacements) Create(value string, isRegex bool) error

func (*Replacements) Delete

func (db *Replacements) Delete(replacementId int64) error

func (*Replacements) List

func (db *Replacements) List() ([]Replacement, error)

type ReplacementsStorage

type ReplacementsStorage interface {
	Create(value string, isRegex bool) error
	Delete(replacementId int64) error
	List() ([]Replacement, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL