stats

package
v0.0.0-...-9914b64 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 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

Overview

Package stats serves POST /api/stats — the instance-wide counters shown on the about page and consumed by external instance listings.

Index

Constants

View Source
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 のほうが安全。

func (*Handler) DropLocal

func (h *Handler) DropLocal()

DropLocal drops the totals held by this process (#3738). 他のプロセスへは 伝えない。

func (*Handler) Stats

func (h *Handler) Stats(c *echo.Context) error

Stats returns instance-wide counters. POST /api/stats

Jump to

Keyboard shortcuts

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