mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-20 11:01:56 +00:00
feat(scopes): import cached regional MeshMapper catalogues
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: meshmapper.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getScopeCatalogue = `-- name: GetScopeCatalogue :one
|
||||
|
||||
SELECT iata, url, payload, etag, checked_at, attempted_at, next_attempt, last_error FROM meshmapper_scope_catalogues WHERE iata = $1 AND url = $2
|
||||
`
|
||||
|
||||
type GetScopeCatalogueParams struct {
|
||||
Iata string `json:"iata"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
// Copyright 2026 Beacon Contributors
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
func (q *Queries) GetScopeCatalogue(ctx context.Context, arg GetScopeCatalogueParams) (MeshmapperScopeCatalogue, error) {
|
||||
row := q.db.QueryRow(ctx, getScopeCatalogue, arg.Iata, arg.Url)
|
||||
var i MeshmapperScopeCatalogue
|
||||
err := row.Scan(
|
||||
&i.Iata,
|
||||
&i.Url,
|
||||
&i.Payload,
|
||||
&i.Etag,
|
||||
&i.CheckedAt,
|
||||
&i.AttemptedAt,
|
||||
&i.NextAttempt,
|
||||
&i.LastError,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const saveScopeCatalogue = `-- name: SaveScopeCatalogue :exec
|
||||
WITH inserted AS (
|
||||
INSERT INTO transport_scopes (name, transport_key, key_fingerprint, imported_only)
|
||||
SELECT entry.name, entry.key, entry.fingerprint, TRUE
|
||||
FROM (SELECT unnest($9::text[]) AS name, unnest($10::bytea[]) AS key,
|
||||
unnest($11::bytea[]) AS fingerprint) AS entry
|
||||
ON CONFLICT (name) DO NOTHING
|
||||
)
|
||||
INSERT INTO meshmapper_scope_catalogues (iata, url, payload, etag, checked_at, attempted_at, next_attempt, last_error)
|
||||
VALUES ($1, $2, $3::jsonb, $4::text,
|
||||
$5::timestamptz, $6, $7, $8)
|
||||
ON CONFLICT (iata, url) DO UPDATE SET
|
||||
payload = COALESCE(EXCLUDED.payload, meshmapper_scope_catalogues.payload),
|
||||
etag = COALESCE(EXCLUDED.etag, meshmapper_scope_catalogues.etag),
|
||||
checked_at = COALESCE(EXCLUDED.checked_at, meshmapper_scope_catalogues.checked_at),
|
||||
attempted_at = EXCLUDED.attempted_at,
|
||||
next_attempt = EXCLUDED.next_attempt,
|
||||
last_error = EXCLUDED.last_error
|
||||
`
|
||||
|
||||
type SaveScopeCatalogueParams struct {
|
||||
Iata string `json:"iata"`
|
||||
Url string `json:"url"`
|
||||
Payload []byte `json:"payload"`
|
||||
Etag *string `json:"etag"`
|
||||
CheckedAt pgtype.Timestamptz `json:"checked_at"`
|
||||
AttemptedAt pgtype.Timestamptz `json:"attempted_at"`
|
||||
NextAttempt pgtype.Timestamptz `json:"next_attempt"`
|
||||
LastError string `json:"last_error"`
|
||||
Names []string `json:"names"`
|
||||
Keys [][]byte `json:"keys"`
|
||||
Fingerprints [][]byte `json:"fingerprints"`
|
||||
}
|
||||
|
||||
// One statement commits the validated snapshot and its lookup identities together.
|
||||
// Empty arrays insert nothing. NULL payload/checked_at retain last-known-good data
|
||||
// after an error or 304. Imported names never replace existing manual metadata.
|
||||
func (q *Queries) SaveScopeCatalogue(ctx context.Context, arg SaveScopeCatalogueParams) error {
|
||||
_, err := q.db.Exec(ctx, saveScopeCatalogue,
|
||||
arg.Iata,
|
||||
arg.Url,
|
||||
arg.Payload,
|
||||
arg.Etag,
|
||||
arg.CheckedAt,
|
||||
arg.AttemptedAt,
|
||||
arg.NextAttempt,
|
||||
arg.LastError,
|
||||
arg.Names,
|
||||
arg.Keys,
|
||||
arg.Fingerprints,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -714,6 +714,21 @@ func (mr *MockQuerierMockRecorder) GetScopeByName(ctx, name any) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetScopeByName", reflect.TypeOf((*MockQuerier)(nil).GetScopeByName), ctx, name)
|
||||
}
|
||||
|
||||
// GetScopeCatalogue mocks base method.
|
||||
func (m *MockQuerier) GetScopeCatalogue(ctx context.Context, arg db.GetScopeCatalogueParams) (db.MeshmapperScopeCatalogue, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetScopeCatalogue", ctx, arg)
|
||||
ret0, _ := ret[0].(db.MeshmapperScopeCatalogue)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetScopeCatalogue indicates an expected call of GetScopeCatalogue.
|
||||
func (mr *MockQuerierMockRecorder) GetScopeCatalogue(ctx, arg any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetScopeCatalogue", reflect.TypeOf((*MockQuerier)(nil).GetScopeCatalogue), ctx, arg)
|
||||
}
|
||||
|
||||
// GetScopeNames mocks base method.
|
||||
func (m *MockQuerier) GetScopeNames(ctx context.Context) ([]string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@@ -1542,6 +1557,20 @@ func (mr *MockQuerierMockRecorder) ResolvePathHashesP4(ctx, arg any) *gomock.Cal
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResolvePathHashesP4", reflect.TypeOf((*MockQuerier)(nil).ResolvePathHashesP4), ctx, arg)
|
||||
}
|
||||
|
||||
// SaveScopeCatalogue mocks base method.
|
||||
func (m *MockQuerier) SaveScopeCatalogue(ctx context.Context, arg db.SaveScopeCatalogueParams) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SaveScopeCatalogue", ctx, arg)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SaveScopeCatalogue indicates an expected call of SaveScopeCatalogue.
|
||||
func (mr *MockQuerierMockRecorder) SaveScopeCatalogue(ctx, arg any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveScopeCatalogue", reflect.TypeOf((*MockQuerier)(nil).SaveScopeCatalogue), ctx, arg)
|
||||
}
|
||||
|
||||
// SearchKnownRoutes mocks base method.
|
||||
func (m *MockQuerier) SearchKnownRoutes(ctx context.Context, arg db.SearchKnownRoutesParams) ([]db.SearchKnownRoutesRow, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@@ -234,6 +234,17 @@ type KnownRoute struct {
|
||||
LastReconfirmedAt pgtype.Timestamptz `json:"last_reconfirmed_at"`
|
||||
}
|
||||
|
||||
type MeshmapperScopeCatalogue struct {
|
||||
Iata string `json:"iata"`
|
||||
Url string `json:"url"`
|
||||
Payload []byte `json:"payload"`
|
||||
Etag *string `json:"etag"`
|
||||
CheckedAt pgtype.Timestamptz `json:"checked_at"`
|
||||
AttemptedAt pgtype.Timestamptz `json:"attempted_at"`
|
||||
NextAttempt pgtype.Timestamptz `json:"next_attempt"`
|
||||
LastError string `json:"last_error"`
|
||||
}
|
||||
|
||||
type MvHourlyIataStat struct {
|
||||
Iata string `json:"iata"`
|
||||
Hour pgtype.Timestamptz `json:"hour"`
|
||||
@@ -528,4 +539,5 @@ type TransportScope struct {
|
||||
TransportKey []byte `json:"transport_key"`
|
||||
KeyFingerprint []byte `json:"key_fingerprint"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
ImportedOnly bool `json:"imported_only"`
|
||||
}
|
||||
|
||||
@@ -89,6 +89,9 @@ type Querier interface {
|
||||
GetRegionIATAs(ctx context.Context, regionID int32) ([]string, error)
|
||||
GetRouteEvidenceRoute(ctx context.Context, arg GetRouteEvidenceRouteParams) (KnownRoute, error)
|
||||
GetScopeByName(ctx context.Context, name string) (GetScopeByNameRow, error)
|
||||
// Copyright 2026 Beacon Contributors
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
GetScopeCatalogue(ctx context.Context, arg GetScopeCatalogueParams) (MeshmapperScopeCatalogue, error)
|
||||
GetScopeNames(ctx context.Context) ([]string, error)
|
||||
// Aggregate matching observations once, separately from node memberships to avoid
|
||||
// a cross-join. Empty IATAs keep the original global counts, including associations
|
||||
@@ -250,6 +253,10 @@ type Querier interface {
|
||||
ResolvePathHashesP2(ctx context.Context, arg ResolvePathHashesP2Params) ([]ResolvePathHashesP2Row, error)
|
||||
ResolvePathHashesP3(ctx context.Context, arg ResolvePathHashesP3Params) ([]ResolvePathHashesP3Row, error)
|
||||
ResolvePathHashesP4(ctx context.Context, arg ResolvePathHashesP4Params) ([]ResolvePathHashesP4Row, error)
|
||||
// One statement commits the validated snapshot and its lookup identities together.
|
||||
// Empty arrays insert nothing. NULL payload/checked_at retain last-known-good data
|
||||
// after an error or 304. Imported names never replace existing manual metadata.
|
||||
SaveScopeCatalogue(ctx context.Context, arg SaveScopeCatalogueParams) error
|
||||
// Returns known routes containing a subsequence from source to destination hash prefix.
|
||||
// Verifies source appears before destination in the route.
|
||||
SearchKnownRoutes(ctx context.Context, arg SearchKnownRoutesParams) ([]SearchKnownRoutesRow, error)
|
||||
|
||||
@@ -2051,7 +2051,7 @@ func (q *Queries) GetTransportScopeByName(ctx context.Context, name string) (int
|
||||
}
|
||||
|
||||
const getTransportScopes = `-- name: GetTransportScopes :many
|
||||
SELECT name, transport_key, key_fingerprint FROM transport_scopes ORDER BY name
|
||||
SELECT name, transport_key, key_fingerprint FROM transport_scopes WHERE NOT imported_only ORDER BY name
|
||||
`
|
||||
|
||||
type GetTransportScopesRow struct {
|
||||
@@ -5228,7 +5228,8 @@ VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (name) DO UPDATE SET
|
||||
display_name = EXCLUDED.display_name,
|
||||
transport_key = EXCLUDED.transport_key,
|
||||
key_fingerprint = EXCLUDED.key_fingerprint
|
||||
key_fingerprint = EXCLUDED.key_fingerprint,
|
||||
imported_only = FALSE
|
||||
`
|
||||
|
||||
type UpsertTransportScopeParams struct {
|
||||
|
||||
Reference in New Issue
Block a user