like malachite (atproto-lastfm-importer) but in go and bluer
go spotify tealfm lastfm atproto
at main 65 lines 2.1 kB view raw
1package cache 2 3import ( 4 "iter" 5 "time" 6) 7 8// RecordStore handles record persistence operations. 9// Iterator methods use iter.Seq2 for iteration, with keys and values 10// cloned to memory to avoid holding read locks during iteration. 11type RecordStore interface { 12 // SaveRecords stores records for a given DID. 13 SaveRecords(did string, records map[string][]byte) error 14 15 // IterateUnpublished iterates over unpublished records. 16 // The iterator yields (key, record) pairs. 17 // If reverse is true, iterates in reverse order using Cursor.Last/Cursor.Prev. 18 IterateUnpublished(did string, reverse bool) iter.Seq2[string, []byte] 19 20 // IteratePublished iterates over published records. 21 // The iterator yields (key, record) pairs. 22 // If reverse is true, iterates in reverse order using Cursor.Last/Cursor.Prev. 23 IteratePublished(did string, reverse bool) iter.Seq2[string, []byte] 24 25 // IterateFailed iterates over failed records. 26 // Returns a function that yields (key, record, errorMessage) triples. 27 IterateFailed(did string) func(yield func(key string, rec []byte, errMsg string) bool) 28 29 MarkPublished(did string, keys ...string) error 30 MarkFailed(did string, keys []string, err string) error 31 RemoveFailed(did string, keys ...string) error 32 GetPublished(did string) (map[string]bool, error) 33 34 Clear(did string) error 35 Close() error 36} 37 38// QuotaStore handles rate limit quota tracking. 39type QuotaStore interface { 40 GetMulti(keys []string) (map[string]int, error) 41 IncrByMulti(counts map[string]int) error 42} 43 44// Storage combines RecordStore and QuotaStore interfaces. 45// Provided for backwards compatibility. 46type Storage interface { 47 RecordStore 48 QuotaStore 49 50 IsValid(did string) bool 51 Timestamp(did string) (time.Time, error) 52 53 ClearAll() error 54 55 // Stats returns database statistics 56 Stats() (DBStats, error) 57} 58 59type DBStats struct { 60 TotalRecords int `json:"totalRecords"` 61 MarkedPublished int `json:"markedPublished"` 62 FailedCount int `json:"failedCount"` 63 UnpublishedCount int `json:"unpublishedCount"` 64 UserStats map[string]any `json:"userStats"` 65}