[DEPRECATED] Go implementation of plcbundle

helpers

+50 -6
+43
bundle/helpers.go
··· 1 + package bundle 2 + 3 + import ( 4 + "fmt" 5 + "time" 6 + ) 7 + 8 + // formatTimeDistance formats a duration as "X ago" or "live" 9 + func formatTimeDistance(d time.Duration) string { 10 + if d < 10*time.Second { 11 + return "live" 12 + } 13 + if d < time.Minute { 14 + return fmt.Sprintf("%ds ago", int(d.Seconds())) 15 + } 16 + if d < time.Hour { 17 + return fmt.Sprintf("%dm ago", int(d.Minutes())) 18 + } 19 + if d < 24*time.Hour { 20 + hours := int(d.Hours()) 21 + mins := int(d.Minutes()) % 60 22 + if mins > 0 { 23 + return fmt.Sprintf("%dh%dm ago", hours, mins) 24 + } 25 + return fmt.Sprintf("%dh ago", hours) 26 + } 27 + days := int(d.Hours() / 24) 28 + if days == 1 { 29 + return "1 day ago" 30 + } 31 + if days < 7 { 32 + return fmt.Sprintf("%d days ago", days) 33 + } 34 + weeks := days / 7 35 + if weeks < 4 { 36 + return fmt.Sprintf("%d weeks ago", weeks) 37 + } 38 + months := days / 30 39 + if months < 12 { 40 + return fmt.Sprintf("%d months ago", months) 41 + } 42 + return fmt.Sprintf("%.1f years ago", float64(days)/365) 43 + }
+4 -3
bundle/manager.go
··· 56 56 cacheMu sync.RWMutex 57 57 maxCacheSize int 58 58 59 - // NEW: Resolver performance tracking 59 + // Resolver performance tracking 60 60 resolverStats struct { 61 61 sync.Mutex 62 62 totalResolutions int64 ··· 596 596 if indexUpdateDuration > 0 { 597 597 msg += fmt.Sprintf(" | index: %s", indexUpdateDuration.Round(time.Millisecond)) 598 598 } 599 + msg += fmt.Sprintf(" | %s", formatTimeDistance(time.Since(bundle.EndTime))) 599 600 m.logger.Println(msg) 600 601 } 601 602 ··· 1425 1426 } 1426 1427 1427 1428 result.Document = doc 1428 - result.LatestOperation = latestMempoolOp // NEW: Include the operation 1429 + result.LatestOperation = latestMempoolOp 1429 1430 result.Source = "mempool" 1430 1431 result.TotalTime = time.Since(totalStart) 1431 1432 ··· 1490 1491 } 1491 1492 1492 1493 result.Document = doc 1493 - result.LatestOperation = op // NEW: Include the operation 1494 + result.LatestOperation = op 1494 1495 result.Source = "bundle" 1495 1496 result.TotalTime = time.Since(totalStart) 1496 1497
+1 -1
bundle/types.go
··· 113 113 LastBundle int 114 114 MissingGaps []int 115 115 TotalSize int64 // Compressed size 116 - TotalUncompressed int64 // Uncompressed size (NEW) 116 + TotalUncompressed int64 117 117 IndexUpdated bool 118 118 } 119 119
+1 -1
internal/didindex/manager.go
··· 283 283 // Determine search range using prefix index 284 284 left, right := 0, int(entryCount) 285 285 286 - // NEW: Use prefix index to narrow range (only for v3+) 286 + // Use prefix index to narrow range (only for v3+) 287 287 if version >= 3 && len(identifier) > 0 { 288 288 prefixByte := identifier[0] 289 289 prefixIndexPos := 32 + (int(prefixByte) * 4)
+1 -1
server/handlers.go
··· 472 472 didIndex.TotalLookups = totalLookups 473 473 } 474 474 475 - // NEW: Lookup performance metrics 475 + // Lookup performance metrics 476 476 if avgTime, ok := didStats["avg_lookup_time_ms"].(float64); ok { 477 477 didIndex.AvgLookupTimeMs = avgTime 478 478 }