Skip to content

Commit

Permalink
♻️ use Count(&count)
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0q committed Jun 3, 2023
1 parent 1ffb11a commit f47d40f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions migration/v13.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package migration

import (
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -65,6 +64,7 @@ ORDER BY
for _, e := range duplicatedEvents {
i := 1
for {
var count int64
if err := tx.
Table("events").
Where(
Expand All @@ -73,13 +73,15 @@ ORDER BY
e.TimeStart,
e.TimeEnd,
).
Take(&map[string]any{}).
Count(&count).
Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
break
}
return err
}

if count == 0 {
break
}

i++
}

Expand Down
12 changes: 7 additions & 5 deletions migration/v14.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package migration

import (
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -65,6 +64,7 @@ ORDER BY
for _, r := range duplicatedRooms {
i := 1
for {
var count int64
if err := tx.
Table("rooms").
Where(
Expand All @@ -73,13 +73,15 @@ ORDER BY
r.TimeStart,
r.TimeEnd,
).
Take(&map[string]any{}).
Count(&count).
Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
break
}
return err
}

if count == 0 {
break
}

i++
}

Expand Down

0 comments on commit f47d40f

Please sign in to comment.