mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat(storage): migrate config, dedup and delivery state to D1
- Move oversized queue payloads from KV to R2 (PAYLOAD binding, webhooks/YYYY/MM/DD/*.json, KV queue:payload:* fallback)
- Persist routes/groups to D1 (d1_routes/d1_groups) with memory -> KV -> D1 three-tier cache, seeded from legacy KV config keys
- Move webhook dedup (dedup_keys), delivery state (delivery_state) and message tracking (message_tracking) to D1 via canUseD1 probe with automatic KV fallback
- Batch send_logs inserts (recordSendBatch) and add group_id/ts index
- Add storage-prune scheduled task for expired dedup/state/tracking rows
- Add TTL to invite:group:{id} index and audit all ephemeral KV keys
- Add D1 indexes for the new tables
- Sync AGENTS.md, README.md/zh and docs/ (en/zh) with the new storage layout
This commit is contained in:
parent
2e1b0f022e
commit
25ebae4ae5
46 changed files with 1450 additions and 117 deletions
28
migrations/0006_config_d1.sql
Normal file
28
migrations/0006_config_d1.sql
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
CREATE TABLE IF NOT EXISTS d1_groups (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
data TEXT NOT NULL,
|
||||
version INTEGER NOT NULL DEFAULT 1,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS d1_routes (
|
||||
id TEXT NOT NULL,
|
||||
group_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
enabled INTEGER NOT NULL DEFAULT 1,
|
||||
filters TEXT NOT NULL,
|
||||
targets TEXT NOT NULL,
|
||||
stop INTEGER NOT NULL DEFAULT 0,
|
||||
fallback INTEGER NOT NULL DEFAULT 0,
|
||||
discord_role_ids TEXT,
|
||||
ast TEXT,
|
||||
version INTEGER NOT NULL DEFAULT 1,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
PRIMARY KEY (id, group_id),
|
||||
FOREIGN KEY (group_id) REFERENCES d1_groups(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_d1_routes_group_id ON d1_routes(group_id);
|
||||
1
migrations/0007_send_logs_index.sql
Normal file
1
migrations/0007_send_logs_index.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
CREATE INDEX IF NOT EXISTS idx_send_logs_group_id_ts ON send_logs (group_id, ts DESC);
|
||||
25
migrations/0008_storage_d1.sql
Normal file
25
migrations/0008_storage_d1.sql
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
-- D1 tables replacing ephemeral high-frequency KV keys (dedup, delivery state,
|
||||
-- message tracking). Keeps KV for things that still benefit from key-based
|
||||
-- access with short TTL; these tables relieve the KV write quota.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dedup_keys (
|
||||
key TEXT PRIMARY KEY,
|
||||
claimed_at INTEGER NOT NULL,
|
||||
expires_at INTEGER NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_dedup_keys_expires_at ON dedup_keys (expires_at);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS delivery_state (
|
||||
key TEXT PRIMARY KEY,
|
||||
status TEXT NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message_tracking (
|
||||
event_id TEXT NOT NULL,
|
||||
target_id TEXT NOT NULL,
|
||||
message_id TEXT NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
PRIMARY KEY (event_id, target_id)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_message_tracking_updated_at ON message_tracking (updated_at);
|
||||
Loading…
Add table
Add a link
Reference in a new issue