163 lines
6.7 KiB
Bash
Executable File
163 lines
6.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Bulk seed the relay with ~1000 test events for the Cleanup page.
|
|
# Generates events across multiple kinds, authors, and age ranges.
|
|
#
|
|
# Usage: ./tests/seed_cleanup_test_events.sh [relay_url]
|
|
# Default relay: ws://127.0.0.1:8888
|
|
|
|
RELAY="${1:-ws://127.0.0.1:8888}"
|
|
ADMIN_SK="1111111111111111111111111111111111111111111111111111111111111111"
|
|
|
|
# Pre-generate 10 random author keys for "non-followed" variety
|
|
RANDOM_SKS=()
|
|
echo "Generating random author keys..."
|
|
for i in $(seq 1 10); do
|
|
RANDOM_SKS+=("$(nak key generate 2>/dev/null | head -1)")
|
|
done
|
|
|
|
NOW=$(date +%s)
|
|
POSTED=0
|
|
FAILED=0
|
|
|
|
# ── Post a single event ─────────────────────────────────────────────────
|
|
post_event() {
|
|
local kind="$1"
|
|
local content="$2"
|
|
local created_at="$3"
|
|
local author_sk="$4"
|
|
|
|
nak event -c "$content" --kind "$kind" --sec "$author_sk" --created-at "$created_at" "$RELAY" >/dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
POSTED=$((POSTED + 1))
|
|
else
|
|
FAILED=$((FAILED + 1))
|
|
fi
|
|
}
|
|
|
|
# ── Post N events in a loop ─────────────────────────────────────────────
|
|
# Usage: bulk_post <kind> <content_prefix> <count> <age_range_days> [author_sk]
|
|
# age_range_days: events will be spread from 0 to N days old
|
|
bulk_post() {
|
|
local kind="$1"
|
|
local prefix="$2"
|
|
local count="$3"
|
|
local age_range="$4"
|
|
local author_sk="${5:-$ADMIN_SK}"
|
|
|
|
for i in $(seq 1 "$count"); do
|
|
local age_seconds=$(( (i * age_range * 86400) / count ))
|
|
local ts=$(( NOW - age_seconds ))
|
|
post_event "$kind" "${prefix} #${i}" "$ts" "$author_sk"
|
|
done
|
|
}
|
|
|
|
# ── Post N events with random author cycling ────────────────────────────
|
|
bulk_post_random() {
|
|
local kind="$1"
|
|
local prefix="$2"
|
|
local count="$3"
|
|
local age_range="$4"
|
|
|
|
for i in $(seq 1 "$count"); do
|
|
local author_sk="${RANDOM_SKS[$(( (i - 1) % ${#RANDOM_SKS[@]} ))]}"
|
|
local age_seconds=$(( (i * age_range * 86400) / count ))
|
|
local ts=$(( NOW - age_seconds ))
|
|
post_event "$kind" "${prefix} #${i}" "$ts" "$author_sk"
|
|
done
|
|
}
|
|
|
|
echo "=== Seeding ~1000 test events to $RELAY ==="
|
|
echo ""
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════
|
|
# ADMIN (FOLLOWED) EVENTS
|
|
# ═══════════════════════════════════════════════════════════════════════
|
|
|
|
echo "--- Admin (followed) events ---"
|
|
|
|
# Kind 1 (text notes) — 100 events spread over 365 days
|
|
bulk_post 1 "Admin text note" 100 365
|
|
|
|
# Kind 7 (reactions) — 50 events spread over 180 days
|
|
bulk_post 7 "+" 50 180
|
|
|
|
# Kind 9734 (zap requests) — 30 events spread over 90 days
|
|
bulk_post 9734 "Zap request" 30 90
|
|
|
|
# Kind 30023 (long-form articles) — 20 events spread over 365 days
|
|
bulk_post 30023 "Long form article content for testing the cleanup page with some substantial text to make the events larger and more realistic" 20 365
|
|
|
|
# Kind 3 (contact lists) — 10 events spread over 365 days
|
|
bulk_post 3 '{"contacts":[]}' 10 365
|
|
|
|
# Kind 0 (profiles) — 5 events spread over 365 days
|
|
for i in $(seq 1 5); do
|
|
ts=$(( NOW - (i * 365 * 86400 / 5) ))
|
|
post_event 0 "{\"name\":\"admin_$i\",\"display_name\":\"Admin User $i\",\"about\":\"Test profile $i\"}" "$ts"
|
|
done
|
|
|
|
echo " → Admin done: $POSTED posted, $FAILED failed"
|
|
echo ""
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════
|
|
# RANDOM (NON-FOLLOWED) EVENTS — bulk of the data
|
|
# ═══════════════════════════════════════════════════════════════════════
|
|
|
|
echo "--- Random (non-followed) events ---"
|
|
|
|
# Kind 1 (text notes) — 400 events spread over 365 days, 10 different authors
|
|
bulk_post_random 1 "Random text note" 400 365
|
|
|
|
# Kind 7 (reactions) — 150 events spread over 180 days
|
|
bulk_post_random 7 "+" 150 180
|
|
|
|
# Kind 9734 (zap requests) — 80 events spread over 90 days
|
|
bulk_post_random 9734 "Zap request" 80 90
|
|
|
|
# Kind 30023 (long-form articles) — 50 events spread over 365 days
|
|
bulk_post_random 30023 "Long form article from random user with some substantial content for testing the cleanup page event deletion functionality" 50 365
|
|
|
|
# Kind 3 (contact lists) — 30 events spread over 365 days
|
|
bulk_post_random 3 '{"contacts":[]}' 30 365
|
|
|
|
# Kind 0 (profiles) — 20 events spread over 365 days
|
|
for i in $(seq 1 20); do
|
|
author_sk="${RANDOM_SKS[$(( (i - 1) % ${#RANDOM_SKS[@]} ))]}"
|
|
ts=$(( NOW - (i * 365 * 86400 / 20) ))
|
|
post_event 0 "{\"name\":\"random_$i\",\"display_name\":\"Random User $i\",\"about\":\"Test profile $i\"}" "$ts" "$author_sk"
|
|
done
|
|
|
|
# Kind 6 (reposts) — 30 events spread over 60 days
|
|
bulk_post_random 6 "Repost content" 30 60
|
|
|
|
# Kind 9735 (zap receipt) — 20 events spread over 30 days
|
|
bulk_post_random 9735 "Zap receipt" 20 30
|
|
|
|
echo " → Random done: $POSTED posted, $FAILED failed"
|
|
echo ""
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════
|
|
# SUMMARY
|
|
# ═══════════════════════════════════════════════════════════════════════
|
|
|
|
echo "=== Done! ==="
|
|
echo " Total posted: $POSTED"
|
|
echo " Total failed: $FAILED"
|
|
echo ""
|
|
echo "Now open http://127.0.0.1:8088/index.php and click 'Cleanup' in the nav."
|
|
echo ""
|
|
echo "Suggested tests:"
|
|
echo " 1. Preview: non-follows, kinds=1, max_age=90"
|
|
echo " → should match random kind-1 events older than 90 days"
|
|
echo " 2. Preview: non-follows, kinds=1,7, max_age=30"
|
|
echo " → should match random kind-1/7 events older than 30 days"
|
|
echo " 3. Preview: follows, kinds=1, max_age=90"
|
|
echo " → should match admin kind-1 events older than 90 days"
|
|
echo " 4. Preview: all, kinds=0"
|
|
echo " → should match all kind-0 (profiles)"
|
|
echo " 5. Preview: non-follows, kinds=30023, max_age=30"
|
|
echo " → should match old random long-form articles"
|
|
echo " 6. Save a query, then execute it"
|
|
echo " 7. Check the kind breakdown to see size distribution"
|