its for when you want to get like notifications for your reposts

fix: remove actor data if no subscriber is using it

ptr.pet 76405e9f 931a7578

verified
+13 -11
+13 -11
server/main.go
··· 110 110 func unmarkActorForLikes(sid string, did syntax.DID) { 111 111 if ud, exists := actorData.Get(did); exists { 112 112 ud.targets.Del(sid) 113 + // remove actor data if no subscribers are attached to it 114 + if ud.targets.Len() == 0 { 115 + actorData.Del(did) 116 + } 113 117 } 114 118 } 115 119 ··· 298 302 logger.Error("like record not found", "rkey", rkey) 299 303 return nil 300 304 } 301 - } else { 302 - if err := json.Unmarshal(event.Commit.Record, &like); err != nil { 303 - logger.Error("failed to unmarshal like", "error", err) 304 - return nil 305 - } 305 + } else if err := unmarshalEvent(event, &like); err != nil { 306 + return nil 306 307 } 307 308 308 309 // if there is no via it means its not a repost anyway ··· 329 330 return true 330 331 } 331 332 332 - if ud.profile == nil || time.Now().Sub(ud.profileFetchedAt) > time.Hour*24 { 333 + if ud.profile == nil || time.Since(ud.profileFetchedAt) > time.Hour*24 { 333 334 profile, err := fetchProfile(ctx, byDid) 334 335 if err != nil { 335 336 logger.Error("cant fetch profile", "error", err) ··· 365 366 366 367 byDid := syntax.DID(event.Did) 367 368 ud, exists := actorData.Get(byDid) 368 - if !exists { 369 + if !exists || ud.targets.Len() == 0 { 369 370 return nil 370 371 } 371 372 ··· 379 380 if f, exists := ud.follows.Get(rkey); exists { 380 381 r = f 381 382 } else { 382 - logger.Error("follow record not found", "rkey", rkey) 383 + // most likely no ListenTypeFollows subscriber attached on actor 384 + logger.Warn("follow record not found", "rkey", rkey, "actor", byDid) 383 385 return nil 384 386 } 385 387 ud.follows.Del(rkey) 386 388 } else { 387 389 if err := unmarshalEvent(event, &r); err != nil { 388 - logger.Error("could not unmarshal follow event", "error", err) 389 390 return nil 390 391 } 391 392 ud.follows.Insert(rkey, r) 392 393 } 394 + 393 395 ud.targets.Range(func(sid string, sd *SubscriberData) bool { 394 396 // if we arent managing then we dont need to update anything 395 397 if sd.listenType != ListenTypeFollows { ··· 412 414 413 415 func unmarshalEvent[v any](event *models.Event, val *v) error { 414 416 if err := json.Unmarshal(event.Commit.Record, val); err != nil { 415 - logger.Error("failed to unmarshal", "error", err, "raw", event.Commit.Record) 416 - return nil 417 + logger.Error("cant unmarshal record", "error", err, "raw", event.Commit.Record) 418 + return err 417 419 } 418 420 return nil 419 421 }