relay filter/appview bootstrap
Prism#
Prism是一个用于gmstn的ATProto AppView服务。它从TAP消费事件,并将其存储/缓存以供将来检索,这样查询就不会对其他PDS造成太大负担。
Prism实现了用于访问缓存feed的XRPC端点。Lexicon定义可以在lexicons/目录中找到。
架构#
ATProto Relay → TAP (backfill + firehose) → Prism (Rust/Axum) → PostgreSQL
↓
XRPC API + WebSocket
本地运行#
前置条件#
Rust, docker/podman
快速开始#
- 启动数据库:
docker compose up postgres tap
# or
podman-compose up postgres tap
- 运行数据库迁移:
export DATABASE_URL=postgres://postgres:postgres@localhost:5432/prism
cargo sqlx migrate run --source migrations
- 运行开发服务器:
cargo run
服务将在 http://localhost:3000 上可用
完整堆栈 (包含TAP)#
docker compose up
这将启动:
- PostgreSQL 端口 5432
- TAP 端口 8080 (HTTP) 和 2480 (WebSocket)
- Prism 端口 3000
API端点#
| 端点 | 描述 |
|---|---|
GET /xrpc/systems.gmstn.development.channel.listChannels?author=<did> |
按作者列出频道 |
GET /xrpc/systems.gmstn.development.channel.listInvites?recipient=<did> |
按接收者列出邀请 |
GET /xrpc/systems.gmstn.development.channel.listMemberships?recipient=<did> |
按接收者列出成员资格 |
GET /xrpc/systems.gmstn.development.lattice.listLattices?author=<did> |
按作者列出晶格 |
GET /xrpc/systems.gmstn.development.shard.listShards?author=<did> |
按作者列出碎片 |
WS /ws |
用于实时记录更新的WebSocket |
所有列表端点都支持limit(1-100,默认50)和cursor(ISO8601时间戳)参数。
配置#
环境变量:
| 变量 | 默认值 | 描述 |
|---|---|---|
DATABASE_URL |
postgres://postgres:postgres@localhost:5432/prism |
PostgreSQL连接字符串 |
TAP_WS_URL |
ws://localhost:2480/channel |
TAP WebSocket URL |
HOST |
0.0.0.0 |
服务器绑定地址 |
PORT |
3000 |
服务器端口 |
RUST_LOG |
prism=info |
日志级别 |
开发#
# 检查代码
cargo check
# 运行测试
cargo test
# 准备sqlx离线缓存(需要运行中的数据库)
cargo sqlx prepare