improve/fix duplicates detection

This commit is contained in:
Niko Storni 2018-09-03 17:38:16 -04:00
parent 6212682e6b
commit 041c0cf056
No known key found for this signature in database
GPG key ID: F37FE63398800368

View file

@ -366,19 +366,21 @@ func logShutdownError(shutdownErr error) {
} }
func hasDupes(claims []jsonrpc.Claim) (bool, error) { func hasDupes(claims []jsonrpc.Claim) (bool, error) {
videoIDs := make(map[string]interface{}) videoIDs := make(map[string]string)
for _, c := range claims { for _, c := range claims {
if !util.InSlice(c.Category, []string{"claim", "update"}) || c.Value.Stream == nil { if !util.InSlice(c.Category, []string{"claim", "update"}) || c.Value.Stream == nil {
continue continue
} }
if c.Value.Stream.Metadata == nil || c.Value.Stream.Metadata.Thumbnail == nil { if c.Value.Stream.Metadata == nil || c.Value.Stream.Metadata.Thumbnail == nil {
return false, errors.Err("something is wrong with the this claim: %s", c.ClaimID) return false, errors.Err("something is wrong with this claim: %s", c.ClaimID)
} }
tn := *c.Value.Stream.Metadata.Thumbnail tn := *c.Value.Stream.Metadata.Thumbnail
videoID := tn[:strings.LastIndex(tn, "/")+1] videoID := tn[strings.LastIndex(tn, "/")+1:]
_, ok := videoIDs[videoID]
if !ok { log.Infof("claimid: %s, claimName: %s, videoID: %s", c.ClaimID, c.Name, videoID)
videoIDs[videoID] = nil cID, ok := videoIDs[videoID]
if !ok || cID == c.ClaimID {
videoIDs[videoID] = c.ClaimID
continue continue
} }
return true, nil return true, nil
@ -425,6 +427,7 @@ func (s *Sync) doSync() error {
} }
} }
if pubsOnWallet > pubsOnDB { if pubsOnWallet > pubsOnDB {
SendInfoToSlack("We're claiming to have published %d videos but in reality we published %d (%s)", pubsOnDB, pubsOnWallet, s.YoutubeChannelID)
return errors.Err("not all published videos are in the database") return errors.Err("not all published videos are in the database")
} }
if pubsOnWallet < pubsOnDB { if pubsOnWallet < pubsOnDB {