End to end on the workstation (coordinator:run, the API, edge:node, real NNTP): a.b.e-book.french and a.b.cd.image.playstation2.dvdiso ranges. - Prefetcher: every connection takes the next missing chunk (leased ranges first, in order); one connection per range (~26k lines/s) kept the worker waiting - executable rule: releases of bare executables (malware floods named after films and software) are dropped; they were 92% of the catalog rows of the test ranges, 21% of the segments - fragments per file (details once) and gzipped batch bodies; the JSON limit (1 MB by default) raised to 256 MB, empty strings kept (a rule count's key is '') - release_chunks.batch_from is a bigint (boneless article numbers) - tests get their own database; edge:bench --store times BatchStore: 1.3 s for a boneless range (1.24 ms per release chunk) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
import db from '@adonisjs/lucid/services/db'
|
|
import { DEFAULT_RULES, type Rules } from '#lib/rules/index'
|
|
|
|
type StoredRules = Omit<Rules, 'version' | 'priorities'>
|
|
|
|
/**
|
|
* The rule set workers get with a lease (REBUILD.md, rules and recovery):
|
|
* the newest version, plus the indexed groups' priorities (owner rule).
|
|
* Version 1 (DEFAULT_RULES, no dropped signatures) is created when there is none.
|
|
*/
|
|
class RuleSets {
|
|
async current(): Promise<Rules> {
|
|
let row = await db.from('rule_sets').orderBy('version', 'desc').first()
|
|
if (!row) {
|
|
const { version: _version, ...rules } = DEFAULT_RULES
|
|
await db.table('rule_sets').insert({ version: 1, rules: JSON.stringify({ ...rules, droppedSignatures: [] }), note: 'default' }).onConflict('version').ignore()
|
|
row = await db.from('rule_sets').orderBy('version', 'desc').first()
|
|
}
|
|
const groups = await db.from('groups').where('active', true).select('name', 'priority')
|
|
const { version: _v, ...defaults } = DEFAULT_RULES
|
|
return {
|
|
// A field newer than the stored set takes today's default.
|
|
...defaults,
|
|
...(row.rules as StoredRules),
|
|
version: Number(row.version),
|
|
priorities: Object.fromEntries(groups.map((g) => [g.name, Number(g.priority)])),
|
|
}
|
|
}
|
|
|
|
/** A new version: what changes is recorded on the ranges that run with it. */
|
|
async publish(rules: StoredRules, note?: string): Promise<number> {
|
|
const latest = await db.from('rule_sets').max('version as v').first()
|
|
const version = Number(latest?.v ?? 0) + 1
|
|
await db.table('rule_sets').insert({ version, rules: JSON.stringify(rules), note: note ?? null })
|
|
return version
|
|
}
|
|
}
|
|
|
|
export default new RuleSets()
|