From 9357c3724c0959a517db73cf8e7a2d41fca1f38d Mon Sep 17 00:00:00 2001 From: gabe Date: Tue, 9 Apr 2024 23:20:31 -0400 Subject: [PATCH] update record logging --- impl/pkg/service/pkarr.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/impl/pkg/service/pkarr.go b/impl/pkg/service/pkarr.go index 171f9e60..0d796388 100644 --- a/impl/pkg/service/pkarr.go +++ b/impl/pkg/service/pkarr.go @@ -196,24 +196,25 @@ func (s *PkarrService) republish() { } var nextPageToken []byte - var allRecords []pkarr.Record - errCnt, successCnt, batchCnt := 0, 0, 0 + var recordsBatch []pkarr.Record + seenRecords, errCnt, successCnt, batchCnt := 0, 0, 0, 0 for { - allRecords, nextPageToken, err = s.db.ListRecords(ctx, nextPageToken, 1000) + recordsBatch, nextPageToken, err = s.db.ListRecords(ctx, nextPageToken, 1000) if err != nil { logrus.WithContext(ctx).WithError(err).Error("failed to list record(s) for republishing") return } + seenRecords += len(recordsBatch) - if len(allRecords) == 0 { + if len(recordsBatch) == 0 { logrus.WithContext(ctx).Info("no records to republish") return } - logrus.WithContext(ctx).WithField("record_count", len(allRecords)).Infof("republishing records in batch: %d", batchCnt) + logrus.WithContext(ctx).WithField("record_count", len(recordsBatch)).Infof("republishing records in batch: %d", batchCnt) batchCnt++ - for _, record := range allRecords { + for _, record := range recordsBatch { recordID := zbase32.EncodeToString(record.Key[:]) logrus.WithContext(ctx).Debugf("republishing record: %s", recordID) if _, err = s.dht.Put(ctx, record.BEP44()); err != nil { @@ -228,9 +229,10 @@ func (s *PkarrService) republish() { break } } + logrus.WithContext(ctx).WithFields(logrus.Fields{ - "success": len(allRecords) - errCnt, + "success": seenRecords - errCnt, "errors": errCnt, - "total": len(allRecords), + "total": seenRecords, }).Infof("republishing complete with [%d] batches", batchCnt) }