Rebuild: the live tail

coordinator:run plans the articles after each group's last range every
TAIL_EVERY_SECONDS (120): one LIST ACTIVE per name prefix gives every
group's newest article, and new articles become ranges at priority -1,
leased and prefetched before any history. A group gets a tail range once
it has TAIL_MIN_ARTICLES (100k, a chunk) new or its last planning is
TAIL_MAX_DELAY_MINUTES (15) ago, so quiet groups don't make a range every
round. History (planAll, hourly) is now only for groups not planned yet.
ranges:plan --tail plans one round.

Found on the way: with XFEATURE COMPRESS GZIP on, Eweka compresses LIST
ACTIVE's reply too ("215 NewsGroups Follow [COMPRESS=GZIP]"), and
listActive waited for a plain end that never came (groups:add --top too).
It reads the compressed reply now; the fake server in the test does both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Opus 5.5 committed 2026-10-09 10:41:16 +02:00
1 parent df89045f98
commit fd0f2bde75
8 files changed
+166 -7

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { test } from '@japa/runner'
import { tailRanges, wildmatOf } from '#services/planner'
const options = { rangeArticles: 1000, minArticles: 100, maxDelayMinutes: 15, priority: -1 }
const now = new Date('2026-10-09T10:00:00Z')
const minutesAgo = (m: number) => new Date(now.getTime() - m * 60_000)
test.group('coordinator / live tail', () => {
test('a chunk of new articles, or a long enough wait, makes tail ranges', ({ assert }) => {
const rows = tailRanges(
[
// Enough new articles: planned at once, cut at rangeArticles.
{ id: 1, plannedTo: 5000, plannedAt: minutesAgo(2), high: 7500 },
// A few new articles, recently planned: waits.
{ id: 2, plannedTo: 100, plannedAt: minutesAgo(2), high: 150 },
// A few new articles, waited long enough.
{ id: 3, plannedTo: 100, plannedAt: minutesAgo(20), high: 103 },
// Nothing new, never planned, not listed: nothing.
{ id: 4, plannedTo: 100, plannedAt: minutesAgo(60), high: 100 },
{ id: 5, plannedTo: null, plannedAt: minutesAgo(60), high: 500 },
{ id: 6, plannedTo: 100, plannedAt: minutesAgo(60), high: null },
],
now,
options
)
assert.deepEqual(
rows.map((r) => [r.group_id, r.start_id, r.end_id, r.next_id, r.priority]),
[
[1, 5001, 6000, 5001, -1],
[1, 6001, 7000, 6001, -1],
[1, 7001, 7500, 7001, -1],
[3, 101, 103, 101, -1],
]
)
})
test('LIST ACTIVE patterns by the first two name parts', ({ assert }) => {
assert.equal(wildmatOf('alt.binaries.boneless'), 'alt.binaries.*')
assert.equal(wildmatOf('alt.binaries.multimedia.anime'), 'alt.binaries.*')
assert.equal(wildmatOf('alt.binaries'), 'alt.binaries')
})
})
+14
View File
@@ -39,6 +39,16 @@ function server(): Promise<{ port: number; close: () => void }> {
sock.write('224 Overview Information Follows\r\n')
send(Buffer.concat([body, Buffer.from('.\r\n')]))
}
} else if (line.startsWith('LIST ACTIVE')) {
// As Eweka: compressed too once XFEATURE COMPRESS GZIP is on.
const body = Buffer.from('a.b.test 102 101 y\r\na.b.other 9000000000 2 y\r\n')
if (gzip) {
sock.write('215 NewsGroups Follow [COMPRESS=GZIP]\r\n')
send(Buffer.concat([deflateSync(body), Buffer.from('.\r\n')]))
} else {
sock.write('215 NewsGroups Follow\r\n')
send(Buffer.concat([body, Buffer.from('.\r\n')]))
}
} else if (line === 'QUIT') sock.end('205 bye\r\n')
}
})
@@ -68,6 +78,10 @@ test.group('nntp / XoverClient', () => {
assert.equal(overviews[1][1].subject, 'Show.S01E01 - "a.mkv" yEnc (2/2)')
assert.deepEqual(await client.xover(1, 1), [])
assert.lengthOf(await client.xover(101, 102), 2)
assert.deepEqual(await client.listActive('a.b.*'), [
{ name: 'a.b.test', high: 102, low: 101 },
{ name: 'a.b.other', high: 9_000_000_000, low: 2 },
])
} finally {
client.close()
close()