Skip to content

Commit e84c8a0

Browse files
committed
checkin: simplify call to get checkin hits since time
1 parent 9462ac3 commit e84c8a0

3 files changed

Lines changed: 6 additions & 10 deletions

File tree

types/checkins/database_hits.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func (h CheckinHitters) Count() int {
2626
return count
2727
}
2828

29+
func (h CheckinHitters) Since(t time.Time) CheckinHitters {
30+
timestamp := db.FormatTime(t)
31+
return CheckinHitters{h.db.Where("checkin_hits.created_at > ?", timestamp)}
32+
}
33+
2934
func (c *Checkin) LastHit() *CheckinHit {
3035
var hit CheckinHit
3136
dbHits.Where("checkin = ?", c.Id).Last(&hit)
@@ -57,8 +62,3 @@ func (c *CheckinHit) Delete() error {
5762
func AllCheckinHits(serviceId int64) CheckinHitters {
5863
return CheckinHitters{dbHits.Joins("JOIN checkins ON checkins.id = checkin").Where("checkins.service = ?", serviceId).Order("checkin_hits.id DESC")}
5964
}
60-
61-
func CheckinHitsSince(serviceId int64, t time.Time) CheckinHitters {
62-
timestamp := db.FormatTime(t)
63-
return CheckinHitters{AllCheckinHits(serviceId).db.Where("checkin_hits.created_at > ?", timestamp)}
64-
}

types/services/hits.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,3 @@ func (s *Service) FirstCheckinHit() *checkins.CheckinHit {
3434
func (s *Service) HitsSince(t time.Time) hits.Hitters {
3535
return hits.Since(t, s)
3636
}
37-
38-
func (s *Service) CheckinHitsSince(t time.Time) checkins.CheckinHitters {
39-
return checkins.CheckinHitsSince(s.Id, t)
40-
}

types/services/methods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (s Service) OnlineDaysPercent(days int) float32 {
278278
func (s *Service) OnlineSince(ago time.Time) float32 {
279279
failsCount := s.FailuresSince(ago).Count()
280280
hitsCount := s.HitsSince(ago).Count()
281-
checkinHitsCount := s.CheckinHitsSince(ago).Count()
281+
checkinHitsCount := s.AllCheckinHits().Since(ago).Count()
282282

283283
if failsCount == 0 {
284284
s.Online24Hours = 100.00

0 commit comments

Comments
 (0)