Skip to content

Growth and XP

XP is not an incrementing counter; it is aggregated from behaviour:

total_xp = Σ(metric count × current value) + Σ(streak milestones × bonus) + Σ(manual adjustments)

Weighting happens at read time: deleting, unliking, unfeaturing, or a moderation rollback reduces XP automatically, and editing a value applies to everyone at once. The recompute path is the only writer of total_xp, trust_level, and level_metrics.

  • level:manage covers /admin/xp-rules and /admin/levels; per-user detail is /admin/users/detail?id=<user id> → “Growth”.

/admin/xp-rules → “Behaviour metrics”: the metric list is fixed, you edit values and caps.

MetricDefaultCapCounts
post_approved_count1025Approved posts, including closed ones
comment_approved_count320Approved comments, excluding post bodies
likes_received_count130Likes on approved content
favorite_received_count2noneTimes your posts were favorited
featured_post_count10nonePosts carrying a featured mark
checkin_count2noneDays checked in

active_day_count and report_upheld_count exist only for retention.

Caps apply per calendar day: counts are grouped by day, truncated to the cap, then summed — with “post = 10, cap 25”, a third post that day adds nothing.

The “Streak ladder” section of /admin/xp-rules. A milestone pays each time a streak lands on it.

Streak days37153060100
Bonus310204080150

Breaking a streak restarts the counter but never claws back earned milestones.

/admin/levels. A level is a row: min_xp, name, retention window, and retention conditions.

LevelDefault nameStart XPWindowRetention
TL0新手上路0—none
TL1基础50100 daysnone
TL2成员200100 daysactive ≥ 10 days, upheld reports ≤ 5
TL3常客500100 daysactive ≥ 50, posts ≥ 10, likes ≥ 20, reports ≤ 3
TL4意见领袖1000—granted manually only (manual_only)

Ranking and retention are one pass: sort enabled levels by min_xp, walk from the highest, skipping manual_only levels and those whose min_xp is not met, and compute each level’s window metrics. The first level whose retention holds wins; otherwise the user drops to the lowest one (window_days = 0 means no conditions), so levels also go down, one step at a time. Admin-set levels (the level_manual flag) survive recompute.

/admin/users/detail?id=<id> → “Growth” → adjustments. Each entry is a ledger row (delta, reason, actor, time); deleting one recomputes and undoes the grant. The same page sets a level by hand, which is how TL4 is awarded.

POST /api/v1/checkin checks in once per day (a unique index enforces it) and returns current streak, best streak, and total days; it grants no XP directly. Badges come from GET /api/v1/badges/list (first post, 7-day streak, 10 likes). Leaderboards use POST /api/v1/leaderboard/list with type = points (total_xp), checkin, or posts.

Recompute converts every input into total_xp, trust_level, and the retention snapshot.

ScopeHowNotes
FullPOST /api/v1/admin/trust/recomputeAdmin button; safe to repeat
Full (CLI)go run main.go -e prod recompute-xpPrints recomputed N users

A 24-hour ticker also runs a full recompute, mainly to demote inactive users; because it re-aggregates rather than accumulates, repeating it never double-counts.

ActionWhy
Deleting a post or commentSoft-deleted rows leave the aggregates
Moderation rollback, or a hit moving content to pendingOnly approved counts
Unliking or unfavoritingThe metric count drops by one
Removing a featured mark, or deleting an adjustmentThe metric or the ledger loses an entry
Prolonged inactivityRetention fails on active days
终端窗口
# XP breakdown for one user (admin)
curl -s http://localhost:8080/api/v1/admin/users/<user_id>/xp \
-H 'Authorization: Bearer <sid>' | jq '.data | {total_xp, trust_level, xp_metrics}'
# Full recompute prints how many users it touched
cd app/server && go run main.go -e prod recompute-xp
SymptomCauseFix
Changing a value moves nobodyRule disabled, or delta=0 skips itEnable it, then refresh the detail
Level is lower than XP suggestsRetention failed (active days, upheld reports)Inspect window metrics
A hand-set level gets revertedNot manual_only, and the user lacks level_manualUse the manual level control, not XP edits
Someone dropped a level overnightDaily full recompute failed retentionExpected
Leaderboard is emptytype misspelled, so it fell back to the defaultUse points, checkin, posts