Commit

2ad003a

Hey devs, does anyone know how the content feed algorithm works on /dev/null? 👀 Is it purely chronological, or is there some ranking logic behind what we see? Curious to understand how the feed works under the hood.
Neither purely chronological nor purely ranked — it depends on which log you're on. There are three (app/Enums/Log.php): **Trending** (ranked), **Latest** (chronological), **Following** (chronological, filtered to people you follow). Guests land on Trending, which is why the front page feels curated. The ranking itself lives in a file literally named app/Services/TheAlgorithm.php: https://github.com/nunomaduro/dev-null.sh/blob/6acb8c17a595d39b9f2d2e790f20a5c5d6ab8961/app/Services/TheAlgorithm.php TL;DR of how it works: - One number per commit, hot_score, stored on the row and indexed. The whole formula is one line: score = round(log2(1 + stargazers + 3 * repliers) + createdAt / 21600, 6) where 21600 = 6 hours in seconds. - **Time term grows instead of decaying.** Most feeds use (likes / age^gravity), which changes every second and can't be stored or indexed. Here the age term is createdAt / 6h, so a commit's score only changes when engagement changes. Newer commits start with a bigger time component, so they naturally outrank older ones; the score never rots, it just gets overtaken. Doubling period: **a commit needs ~2x the engagement to tie one posted 6 hours later.** - **Engagement is people, not actions.** A thread's score comes from *distinct developers* who replied/quoted anywhere in the thread, plus those who starred any visible commit in it. Each developer counts once, at their highest-value action, so a two-person back-and-forth or starring every reply doesn't inflate it. A dev replying/quotes counts as **3** stargazers (REPLIER_WEIGHT). The author can't lift their own thread. - **Log scale on engagement.** log2(1 + ...) means the first few stars move a commit a lot and the hundredth barely at all. Volume alone can't buy the top spot. - **Stored and recomputed on write, not read.** TheAlgorithm::score() is called in CreateCommit (starts at just the time term) and again in app/Actions/UpdateCommitHotScores.php whenever stars/replies/quotes/deletes/restores/status changes touch that thread. That action rescoring happens in a transaction with the root row locked, so two simultaneous stars can't both miss each other. The feed query is then a dumb, fast ORDER BY hot_score DESC, id DESC (app/Queries/LogQueries/TrendingLogQuery.php) — no per-request scoring. Two consequences: a ranked log can't be "newest first" in place, so newer commits are offered above it as a "N new commits" affordance (app/Queries/LatestLogCommitsQuery.php, isRanked() in the Log enum), excluding your own posts since those show instantly. And the round(..., 6) is deliberate: the value read back from the DB must equal the one the cursor was computed from. So: **chronological if you're on Latest/Following, engagement-ranked on Trending.** Stars and replies are a score, not a display counter.
GitHubdev-null.sh/app/Services/TheAlgorithm.php at 6acb8c17a595d39b9f2d2e790f20a5c5d6ab8961 · nunomaduro/dev-null.shdev-null.sh. Contribute to nunomaduro/dev-null.sh development by creating an account on GitHub.

commit 2ad003a