···73737474 _, err = tx.ExecContext(ctx, `
7575 INSERT INTO _feed_sim_staging (feed_a, feed_b, jaccard)
7676- SELECT
7777- s1.feed_url,
7878- s2.feed_url,
7979- SUM(EXP(-0.023 * CAST(julianday('now') - julianday(MIN(s1.added_at, s2.added_at)) AS REAL)))
8080- / (f1.subscriber_count + f2.subscriber_count - CAST(COUNT(*) AS REAL))
8181- FROM articles.subscriptions s1
8282- JOIN articles.subscriptions s2 ON s1.user_did = s2.user_did AND s1.feed_url < s2.feed_url
8383- JOIN articles.feeds f1 ON f1.feed_url = s1.feed_url
8484- JOIN articles.feeds f2 ON f2.feed_url = s2.feed_url
8585- WHERE s1.added_at IS NOT NULL AND s2.added_at IS NOT NULL
8686- GROUP BY s1.feed_url, s2.feed_url
7676+ SELECT feed_a, feed_b, jaccard FROM (
7777+ SELECT
7878+ s1.feed_url AS feed_a,
7979+ s2.feed_url AS feed_b,
8080+ SUM(EXP(-0.023 * CAST(julianday('now') - julianday(MIN(s1.added_at, s2.added_at)) AS REAL)))
8181+ / NULLIF(f1.subscriber_count + f2.subscriber_count - CAST(COUNT(*) AS REAL), 0) AS jaccard
8282+ FROM articles.subscriptions s1
8383+ JOIN articles.subscriptions s2 ON s1.user_did = s2.user_did AND s1.feed_url < s2.feed_url
8484+ JOIN articles.feeds f1 ON f1.feed_url = s1.feed_url
8585+ JOIN articles.feeds f2 ON f2.feed_url = s2.feed_url
8686+ WHERE s1.added_at IS NOT NULL AND s2.added_at IS NOT NULL
8787+ GROUP BY s1.feed_url, s2.feed_url
8888+ ) WHERE jaccard IS NOT NULL
8789 `)
8890 if err != nil {
8991 return err