nandi/gleanpublic⑂ Fork 0
⑂ 8861211
Commits
⬇ Clone ▾
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Fix division by zero in Jaccard similarity calculationUnverified

Julien Robert committed 2026-05-01T22:21:10+02:00 Browse files
8861211 parent: 7c84f4a
modified internal/cluster/jaccard.go +13 -11
@@ -73,17 +73,19 @@ func (e *Engine) ComputeFeedSimilarity(ctx context.Context) error {
7373
7474 _, err = tx.ExecContext(ctx, `
7575 INSERT INTO _feed_sim_staging (feed_a, feed_b, jaccard)
76- SELECT
77- s1.feed_url,
78- s2.feed_url,
79- SUM(EXP(-0.023 * CAST(julianday('now') - julianday(MIN(s1.added_at, s2.added_at)) AS REAL)))
80- / (f1.subscriber_count + f2.subscriber_count - CAST(COUNT(*) AS REAL))
81- FROM articles.subscriptions s1
82- JOIN articles.subscriptions s2 ON s1.user_did = s2.user_did AND s1.feed_url < s2.feed_url
83- JOIN articles.feeds f1 ON f1.feed_url = s1.feed_url
84- JOIN articles.feeds f2 ON f2.feed_url = s2.feed_url
85- WHERE s1.added_at IS NOT NULL AND s2.added_at IS NOT NULL
86- GROUP BY s1.feed_url, s2.feed_url
76+ SELECT feed_a, feed_b, jaccard FROM (
77+ SELECT
78+ s1.feed_url AS feed_a,
79+ s2.feed_url AS feed_b,
80+ SUM(EXP(-0.023 * CAST(julianday('now') - julianday(MIN(s1.added_at, s2.added_at)) AS REAL)))
81+ / NULLIF(f1.subscriber_count + f2.subscriber_count - CAST(COUNT(*) AS REAL), 0) AS jaccard
82+ FROM articles.subscriptions s1
83+ JOIN articles.subscriptions s2 ON s1.user_did = s2.user_did AND s1.feed_url < s2.feed_url
84+ JOIN articles.feeds f1 ON f1.feed_url = s1.feed_url
85+ JOIN articles.feeds f2 ON f2.feed_url = s2.feed_url
86+ WHERE s1.added_at IS NOT NULL AND s2.added_at IS NOT NULL
87+ GROUP BY s1.feed_url, s2.feed_url
88+ ) WHERE jaccard IS NOT NULL
8789 `)
8890 if err != nil {
8991 return err
@@ -73,17 +73,19 @@ func (e *Engine) ComputeFeedSimilarity(ctx context.Context) error {
73 73
74 _, err = tx.ExecContext(ctx, `74 _, err = tx.ExecContext(ctx, `
75 INSERT INTO _feed_sim_staging (feed_a, feed_b, jaccard)75 INSERT INTO _feed_sim_staging (feed_a, feed_b, jaccard)
76- SELECT76+ SELECT feed_a, feed_b, jaccard FROM (
77- s1.feed_url,77+ SELECT
78- s2.feed_url,78+ s1.feed_url AS feed_a,
79- SUM(EXP(-0.023 * CAST(julianday('now') - julianday(MIN(s1.added_at, s2.added_at)) AS REAL)))79+ s2.feed_url AS feed_b,
80- / (f1.subscriber_count + f2.subscriber_count - CAST(COUNT(*) AS REAL))80+ SUM(EXP(-0.023 * CAST(julianday('now') - julianday(MIN(s1.added_at, s2.added_at)) AS REAL)))
81- FROM articles.subscriptions s181+ / NULLIF(f1.subscriber_count + f2.subscriber_count - CAST(COUNT(*) AS REAL), 0) AS jaccard
82- JOIN articles.subscriptions s2 ON s1.user_did = s2.user_did AND s1.feed_url < s2.feed_url82+ FROM articles.subscriptions s1
83- JOIN articles.feeds f1 ON f1.feed_url = s1.feed_url83+ JOIN articles.subscriptions s2 ON s1.user_did = s2.user_did AND s1.feed_url < s2.feed_url
84- JOIN articles.feeds f2 ON f2.feed_url = s2.feed_url84+ JOIN articles.feeds f1 ON f1.feed_url = s1.feed_url
85- WHERE s1.added_at IS NOT NULL AND s2.added_at IS NOT NULL85+ JOIN articles.feeds f2 ON f2.feed_url = s2.feed_url
86- GROUP BY s1.feed_url, s2.feed_url86+ WHERE s1.added_at IS NOT NULL AND s2.added_at IS NOT NULL
87+ GROUP BY s1.feed_url, s2.feed_url
88+ ) WHERE jaccard IS NOT NULL
87 `)89 `)
88 if err != nil {90 if err != nil {
89 return err91 return err