From 5f640aab0c2ce9921f68372bf15d7ad01a3cb85d Mon Sep 17 00:00:00 2001 From: Hoang Pham Date: Thu, 3 Mar 2022 16:19:29 -0600 Subject: [PATCH] FB-1188 - Fixed ttl parseDuration --- encoding/proto/proto.go | 17 +++++------------ hack.go | 15 ++++----------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/encoding/proto/proto.go b/encoding/proto/proto.go index 69c101f3b..105680a4c 100644 --- a/encoding/proto/proto.go +++ b/encoding/proto/proto.go @@ -1073,19 +1073,12 @@ func (s Serializer) decodeFieldOptions(options *pb.FieldOptions, m *pilosa.Field m.Scale = options.Scale m.BitDepth = uint64(options.BitDepth) m.TimeQuantum = pilosa.TimeQuantum(options.TimeQuantum) - // Ttl is optional, it might not exist on some data - // To prevent "ParseDuration error:" logs showwing for the empty Ttl values, set those emtpy Ttl as 0 - if options.Ttl != "" { - ttlVal, err := time.ParseDuration(options.Ttl) - if err != nil { - m.Ttl = 0 - fmt.Println(fmt.Errorf("ParseDuration error: %v", err)) - } else { - m.Ttl = ttlVal - } - } else { - m.Ttl = 0 + ttlValue, err := time.ParseDuration(options.Ttl) + if err != nil { + ttlValue = 0 + fmt.Println(fmt.Errorf("ParseDuration error: %v", err)) } + m.Ttl = ttlValue m.TimeUnit = options.TimeUnit m.Keys = options.Keys m.ForeignIndex = options.ForeignIndex diff --git a/hack.go b/hack.go index 23da607a6..eb1f5787b 100644 --- a/hack.go +++ b/hack.go @@ -59,18 +59,11 @@ func UnmarshalFieldOptions(name string, createdAt int64, buf []byte) (*FieldInfo fi.Options.Base = pbi.Base fi.Options.BitDepth = pbi.BitDepth fi.Options.TimeQuantum = TimeQuantum(pbi.TimeQuantum) - // Ttl is optional, it might not exist on some data - // for the empty Ttl values, set those emtpy Ttl as 0 - if pbi.Ttl != "" { - ttlVal, err := time.ParseDuration(pbi.Ttl) - if err != nil { - fi.Options.Ttl = 0 - } else { - fi.Options.Ttl = ttlVal - } - } else { - fi.Options.Ttl = 0 + ttlValue, err := time.ParseDuration(pbi.Ttl) + if err != nil { + ttlValue = 0 } + fi.Options.Ttl = ttlValue fi.Options.Keys = pbi.Keys fi.Options.NoStandardView = pbi.NoStandardView