split limit determination into separate function
This commit is contained in:
parent
2d742ce3f7
commit
831d4f78e3
19
main.go
19
main.go
|
@ -34,17 +34,23 @@ func formula(p float64) int64 {
|
||||||
return int64(yearsAgo * 31556926)
|
return int64(yearsAgo * 31556926)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *TimelineDB) closestEvents(t int64, n int, after bool, before bool) ([]EventsRow, error) {
|
func limits(t int64, after bool, before bool) (int64, int64, error) {
|
||||||
ulimit := int64(math.MaxInt64)
|
|
||||||
llimit := int64(math.MinInt64)
|
llimit := int64(math.MinInt64)
|
||||||
|
ulimit := int64(math.MaxInt64)
|
||||||
|
var err error
|
||||||
|
|
||||||
if after && before {
|
if after && before {
|
||||||
return nil, errors.New("after and before can't both be true")
|
err = errors.New("after and before can't both be true")
|
||||||
} else if after {
|
} else if after {
|
||||||
llimit = t
|
llimit = t
|
||||||
} else if before {
|
} else if before {
|
||||||
ulimit = t
|
ulimit = t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return llimit, ulimit, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *TimelineDB) closestEvents(t int64, n int, llimit int64, ulimit int64) ([]EventsRow, error) {
|
||||||
query := `
|
query := `
|
||||||
select description, timestamp, yearknown, monthknown, dayknown, hourknown, minuteknown, secondknown
|
select description, timestamp, yearknown, monthknown, dayknown, hourknown, minuteknown, secondknown
|
||||||
from events
|
from events
|
||||||
|
@ -130,7 +136,12 @@ func main() {
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
events, err := db.closestEvents(t, *nevents, *after, *before)
|
llimit, ulimit, err := limits(t, *after, *before)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
events, err := db.closestEvents(t, *nevents, llimit, ulimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue