Documentation
¶
Overview ¶
Package stats serves POST /api/stats — the instance-wide counters shown on the about page and consumed by external instance listings.
Index ¶
Constants ¶
const CountsCacheTTL = time.Hour
CountsCacheTTL is how long the instances / reactionsCount totals are reused.
upstream stats.ts は `noteReactionsRepository.count({ cache: 3600000 })` と `instancesRepository.count({ cache: 3600000 })` で 1 時間キャッシュする。 毎回数えると note_reaction の全件 COUNT (122 万行で 43ms) が、認証なしで 呼べる経路から何度でも走る (#3612)。 キャッシュはプロセスごとに持つ。本家の TypeORM のキャッシュは Redis (`type: 'ioredis'`) で全プロセスが共有するので、複数プロセスで動かすと プロセスごとに数えた時刻がずれる。
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChartReader ¶
type ChartReader interface {
GetChart(ctx context.Context, span chart.Span, amount int, cursor *time.Time, group string) (chart.Result, error)
}
ChartReader is the subset of *chart.Chart this endpoint needs.
**具体型ではなく interface で受ける。** stats が要るのは「直近 1 時間の local / remote の累計」だけで chart engine 全体ではない。テストから任意の 値を入れられるようにもなる。
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the stats endpoint.
func NewHandler ¶
func NewHandler(db *gorm.DB, notesChart, usersChart ChartReader) *Handler
NewHandler creates a stats Handler.
db / chart はいずれも nil を許す。未配線の項目は 0 で返す — upstream の レスポンス shape は全フィールド必須なので、欠けさせるより 0 のほうが安全。