mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01:00
lib/flagutil: add Duration.Milliseconds() convenience function after 0c7d46d637
This function is a faster replacement for Duration.Duration().Milliseconds() call
This commit is contained in:
parent
0c7d46d637
commit
24d61bf193
@ -75,7 +75,7 @@ func CheckTimeRange(tr storage.TimeRange) error {
|
||||
if !*denyQueriesOutsideRetention {
|
||||
return nil
|
||||
}
|
||||
minAllowedTimestamp := int64(fasttime.UnixTimestamp()*1000) - retentionPeriod.Duration().Milliseconds()
|
||||
minAllowedTimestamp := int64(fasttime.UnixTimestamp()*1000) - retentionPeriod.Milliseconds()
|
||||
if tr.MinTimestamp > minAllowedTimestamp {
|
||||
return nil
|
||||
}
|
||||
|
@ -31,11 +31,16 @@ type Duration struct {
|
||||
valueString string
|
||||
}
|
||||
|
||||
// Duration convert to time.Duration.
|
||||
// Duration returns d as time.Duration
|
||||
func (d *Duration) Duration() time.Duration {
|
||||
return time.Millisecond * time.Duration(d.msecs)
|
||||
}
|
||||
|
||||
// Milliseconds returns d in milliseconds
|
||||
func (d *Duration) Milliseconds() int64 {
|
||||
return d.msecs
|
||||
}
|
||||
|
||||
// String implements flag.Value interface
|
||||
func (d *Duration) String() string {
|
||||
return d.valueString
|
||||
|
@ -42,8 +42,8 @@ func TestDurationSetSuccess(t *testing.T) {
|
||||
if err := d.Set(value); err != nil {
|
||||
t.Fatalf("unexpected error in d.Set(%q): %s", value, err)
|
||||
}
|
||||
if d.msecs != expectedMsecs {
|
||||
t.Fatalf("unexpected result; got %d; want %d", d.msecs, expectedMsecs)
|
||||
if d.Milliseconds() != expectedMsecs {
|
||||
t.Fatalf("unexpected result; got %d; want %d", d.Milliseconds(), expectedMsecs)
|
||||
}
|
||||
valueString := d.String()
|
||||
valueExpected := strings.ToLower(value)
|
||||
|
Loading…
Reference in New Issue
Block a user