Add archive relay query augmentation and access-based GC (v0.45.0)

- Add async archive relay querying (local results immediate, archives in background)
- Add query caching with filter normalization to avoid repeated requests
- Add session-deduplicated access tracking for events
- Add continuous garbage collection based on access patterns
- Auto-detect storage limit (80% of filesystem) when ORLY_MAX_STORAGE_BYTES=0
- Support NIP-50 search queries to archive relays

New environment variables:
- ORLY_ARCHIVE_ENABLED: Enable archive relay query augmentation
- ORLY_ARCHIVE_RELAYS: Comma-separated archive relay URLs
- ORLY_ARCHIVE_TIMEOUT_SEC: Archive query timeout
- ORLY_ARCHIVE_CACHE_TTL_HRS: Query deduplication window
- ORLY_GC_ENABLED: Enable access-based garbage collection
- ORLY_MAX_STORAGE_BYTES: Max storage (0=auto 80%)
- ORLY_GC_INTERVAL_SEC: GC check interval
- ORLY_GC_BATCH_SIZE: Events per GC cycle

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
woikos
2026-01-02 19:35:16 +01:00
parent 0008d33792
commit 8a14cec3cd
19 changed files with 1718 additions and 2 deletions

View File

@@ -690,6 +690,31 @@ func (l *Listener) HandleReq(msg []byte) (err error) {
Write(l); chk.E(err) {
return
}
// Record access for returned events (for GC access-based ranking)
if l.accessTracker != nil && len(events) > 0 {
go func(evts event.S, connID string) {
for _, ev := range evts {
if ser, err := l.DB.GetSerialById(ev.ID); err == nil && ser != nil {
l.accessTracker.RecordAccess(ser.Get(), connID)
}
}
}(events, l.connectionID)
}
// Trigger archive relay query if enabled (background fetch + stream results)
if l.archiveManager != nil && l.archiveManager.IsEnabled() && len(*env.Filters) > 0 {
// Use first filter for archive query
f := (*env.Filters)[0]
go l.archiveManager.QueryArchive(
string(env.Subscription),
l.connectionID,
f,
seen,
l, // implements EventDeliveryChannel
)
}
// if the query was for just Ids, we know there can't be any more results,
// so cancel the subscription.
cancel := true