refac: removed ugly multi-line method chaining
This commit is contained in:
1 parent
e8dff6bb5f
commit
ce9c876db6
6 files changed
+72
-67
No files matched your search
@@ -40,10 +40,10 @@ func (v *VariantUsageRepository) Record(batch domain.VariantUsageBatch) error {
|
||||
|
||||
func recordHit(tx *gorm.DB, hit domain.VariantHit) error {
|
||||
at := hit.At.UTC()
|
||||
return tx.Model(&entity.ImageVariantFile{}).
|
||||
Where("variant_name = ? AND source_name = ?", hit.VariantName, hit.SourceName).
|
||||
Where("last_requested_at IS NULL OR last_requested_at < ?", at).
|
||||
Update("last_requested_at", at).Error
|
||||
query := tx.Model(&entity.ImageVariantFile{})
|
||||
query = query.Where("variant_name = ? AND source_name = ?", hit.VariantName, hit.SourceName)
|
||||
query = query.Where("last_requested_at IS NULL OR last_requested_at < ?", at)
|
||||
return query.Update("last_requested_at", at).Error
|
||||
}
|
||||
|
||||
func recordRejections(tx *gorm.DB, rejection domain.RejectionCount) error {
|
||||
@@ -56,9 +56,9 @@ func recordRejections(tx *gorm.DB, rejection domain.RejectionCount) error {
|
||||
|
||||
func (v *VariantUsageRepository) RejectedSince(day time.Time) (int, error) {
|
||||
var total int
|
||||
err := v.db.Model(&entity.ImageVariantRejectionDay{}).
|
||||
Select("COALESCE(SUM(count), 0)").
|
||||
Where("day >= ?", day.UTC().Format(domain.RejectionDayLayout)).
|
||||
Scan(&total).Error
|
||||
query := v.db.Model(&entity.ImageVariantRejectionDay{})
|
||||
query = query.Select("COALESCE(SUM(count), 0)")
|
||||
query = query.Where("day >= ?", day.UTC().Format(domain.RejectionDayLayout))
|
||||
err := query.Scan(&total).Error
|
||||
return total, err
|
||||
}
|
||||
Reference in new issue
Block a user