this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

handle delete evts

dholms ee8e5d81 5d5d1450

+34 -11
+34 -11
nexus/processor.go
··· 243 243 return nil 244 244 } 245 245 246 - // handle delete first 247 - 248 246 var updateTo models.AccountStatus 249 247 if evt.Active { 250 248 updateTo = models.AccountStatusActive 251 - } else if *evt.Status == string(models.AccountStatusDeactivated) || *evt.Status == string(models.AccountStatusTakendown) || *evt.Status == string(models.AccountStatusSuspended) { 249 + } else if *evt.Status == string(models.AccountStatusDeactivated) || *evt.Status == string(models.AccountStatusTakendown) || *evt.Status == string(models.AccountStatusSuspended) || *evt.Status == string(models.AccountStatusDeleted) { 252 250 updateTo = models.AccountStatus(*evt.Status) 253 251 } else { 254 - // NOOP 252 + // no-op for other events such as throttled or desynchronized 255 253 return nil 256 254 } 257 255 ··· 259 257 return nil 260 258 } 261 259 262 - err = ep.DB.Model(&models.Repo{}). 263 - Where("did = ?", evt.Did). 264 - Update("status", updateTo).Error 265 - if err != nil { 266 - ep.Logger.Error("failed to update repo status", "did", evt.Did, "status", models.AccountStatusActive, "error", err) 267 - return err 260 + if updateTo == models.AccountStatusDeleted { 261 + err := ep.DeleteRepo(evt.Did) 262 + if err != nil { 263 + ep.Logger.Error("failed to delete repo", "did", evt.Did, "error", err) 264 + return err 265 + } 266 + } else { 267 + err = ep.DB.Model(&models.Repo{}). 268 + Where("did = ?", evt.Did). 269 + Update("status", updateTo).Error 270 + if err != nil { 271 + ep.Logger.Error("failed to update repo status", "did", evt.Did, "status", models.AccountStatusActive, "error", err) 272 + return err 273 + } 268 274 } 269 275 270 276 err = ep.Outbox.SendUserEvt(&UserEvt{ ··· 273 279 IsActive: evt.Active, 274 280 Status: updateTo, 275 281 }) 276 - 277 282 if err != nil { 278 283 ep.Logger.Error("failed to send user evt", "did", evt.Did, "error", err) 279 284 return err ··· 360 365 return err 361 366 } 362 367 } 368 + } 369 + 370 + return nil 371 + }) 372 + } 373 + 374 + func (ep *EventProcessor) DeleteRepo(did string) error { 375 + return ep.DB.Transaction(func(tx *gorm.DB) error { 376 + if err := tx.Delete(&models.RepoRecord{}, "did = ?", did).Error; err != nil { 377 + return err 378 + } 379 + 380 + if err := tx.Delete(&models.ResyncBuffer{}, "did = ?", did).Error; err != nil { 381 + return err 382 + } 383 + 384 + if err := tx.Delete(&models.Repo{}, "did = ?", did).Error; err != nil { 385 + return err 363 386 } 364 387 365 388 return nil