mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-20 14:32:54 +00:00
* feat(db): background_state table and the (hop_count, iata) route index * perf(db): one /routes statement per filter shape, hop pair on custom plans * feat(db): keyset route retention and grace slices at exact cutoffs * feat(background): hourly route retention with a bounded grace walk and watermark * fix(background): bound the grace walk at microsecond cutoffs * feat(db): stamp-free reconfirm sweep over the route primary key * feat(background): pace route reconfirm at routes.reconfirm_rows_per_hour, no stamps * test(routes): drive route retention end to end and tidy comments * fix(profiling): sample during the hourly route retention run
35 lines
1.4 KiB
Go
35 lines
1.4 KiB
Go
// Copyright 2026 Beacon Contributors
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
sqlc "github.com/MeshCore-Beacon/beacon-server/db/sqlc"
|
|
"github.com/jackc/pgx/v5"
|
|
"github.com/jackc/pgx/v5/pgconn"
|
|
)
|
|
|
|
// unnamedDBTX runs every statement as an unnamed prepared statement (pgx.QueryExecModeCacheDescribe):
|
|
// pgx caches only the description, never a named server-side statement, so Postgres cannot switch it
|
|
// to a generic plan after five executions. Class C statements, whose best plan depends on the values,
|
|
// go through it (Store.qc).
|
|
//
|
|
// Unnamed statements are planned with their values on every call under plan_cache_mode auto or
|
|
// force_custom_plan. force_generic_plan still makes them generic, so a future generic-plan pool
|
|
// must never take these statements.
|
|
type unnamedDBTX struct{ sqlc.DBTX }
|
|
|
|
func (u unnamedDBTX) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error) {
|
|
return u.DBTX.Exec(ctx, sql, append([]any{pgx.QueryExecModeCacheDescribe}, args...)...)
|
|
}
|
|
|
|
func (u unnamedDBTX) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error) {
|
|
return u.DBTX.Query(ctx, sql, append([]any{pgx.QueryExecModeCacheDescribe}, args...)...)
|
|
}
|
|
|
|
func (u unnamedDBTX) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row {
|
|
return u.DBTX.QueryRow(ctx, sql, append([]any{pgx.QueryExecModeCacheDescribe}, args...)...)
|
|
}
|