1
0
Fork 0

Use metadata hash to avoid duped metadata.

This was causing high CPU usage.
main
Icedream 2024-01-22 00:47:44 +01:00
parent 537be95850
commit 126933fb5e
Signed by: icedream
GPG Key ID: 468BBEEBB9EC6AEA
1 changed files with 9 additions and 0 deletions

View File

@ -39,6 +39,7 @@ func init() {
func watchMetadata(ctx context.Context) <-chan *libnp.Info {
ticker := time.NewTicker(time.Second)
c := make(chan *libnp.Info)
var lastMetadataID [64]byte
go func(ticker *time.Ticker) {
for {
select {
@ -50,6 +51,14 @@ func watchMetadata(ctx context.Context) <-chan *libnp.Info {
os.Stderr.WriteString("WARNING: " + err.Error() + "\n")
continue
}
var newMetadataID [64]byte
if info != nil {
newMetadataID = generateIDFromMetadata(*info)
}
if newMetadataID == lastMetadataID {
// metadata did not change
continue
}
c <- info
}
}