fix: stabilize inbox confirmation retries
This commit is contained in:
@@ -165,8 +165,8 @@ func (s *Service) Confirm(itemIdentity string, userID uint, selectedSuggestionId
|
||||
return err
|
||||
}
|
||||
if item.Status != "open" {
|
||||
result.CreatedCount, err = countConfirmedObjects(tx, item.ID, userID)
|
||||
return err
|
||||
result.CreatedCount = item.ConfirmedCount
|
||||
return nil
|
||||
}
|
||||
|
||||
selected, err := normalizeSelectedIdentities(selectedSuggestionIdentities)
|
||||
@@ -195,23 +195,14 @@ func (s *Service) Confirm(itemIdentity string, userID uint, selectedSuggestionId
|
||||
}
|
||||
result.CreatedCount++
|
||||
}
|
||||
return tx.Model(item).Update("status", "processed").Error
|
||||
return tx.Model(item).Updates(map[string]any{
|
||||
"status": "processed",
|
||||
"confirmed_count": result.CreatedCount,
|
||||
}).Error
|
||||
})
|
||||
return result, err
|
||||
}
|
||||
|
||||
func countConfirmedObjects(tx *gorm.DB, inboxItemID, userID uint) (int, error) {
|
||||
total := int64(0)
|
||||
for _, model := range []any{&models.SenlinAgentTask{}, &models.SenlinAgentNote{}, &models.SenlinAgentSource{}} {
|
||||
var count int64
|
||||
if err := tx.Model(model).Where("source_inbox_item_id = ? AND created_by = ?", inboxItemID, userID).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
total += count
|
||||
}
|
||||
return int(total), nil
|
||||
}
|
||||
|
||||
func findOwnedInboxItem(tx *gorm.DB, identity string, userID uint, lock bool) (*models.SenlinAgentInboxItem, error) {
|
||||
var item models.SenlinAgentInboxItem
|
||||
query := tx.Model(&models.SenlinAgentInboxItem{}).
|
||||
|
||||
Reference in New Issue
Block a user