Fix release_time query to match python hub. (#41)
* Revise error handling and cleanup in GetProdDB(). Avoids panic when DB not found. * Fix release_time query to match python hub. Claims with unset release_time match the query.
This commit is contained in:
parent
8b4b27bdb9
commit
49e5d7b8c1
2 changed files with 20 additions and 6 deletions
14
db/db.go
14
db/db.go
|
@ -446,20 +446,24 @@ func GetProdDB(name string, secondaryPath string) (*ReadOnlyDBColumnFamily, func
|
||||||
|
|
||||||
db, err := GetDBColumnFamilies(name, secondaryPath, cfNames)
|
db, err := GetDBColumnFamilies(name, secondaryPath, cfNames)
|
||||||
|
|
||||||
cleanup := func() {
|
cleanupFiles := func() {
|
||||||
db.DB.Close()
|
|
||||||
err = os.RemoveAll(secondaryPath)
|
err = os.RemoveAll(secondaryPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.Cleanup = cleanup
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cleanup, err
|
return nil, cleanupFiles, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return db, cleanup, nil
|
cleanupDB := func() {
|
||||||
|
db.DB.Close()
|
||||||
|
cleanupFiles()
|
||||||
|
}
|
||||||
|
db.Cleanup = cleanupDB
|
||||||
|
|
||||||
|
return db, cleanupDB, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDBColumnFamilies gets a db with the specified column families and secondary path.
|
// GetDBColumnFamilies gets a db with the specified column families and secondary path.
|
||||||
|
|
|
@ -208,6 +208,15 @@ func RoundUpReleaseTime(q *elastic.BoolQuery, rqs []*pb.RangeField, name string)
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FieldUnsetOr takes a bool query, and a term name. A query is constructed
|
||||||
|
// such that either the field does not exist OR the field exists and matches
|
||||||
|
// the original query.
|
||||||
|
func FieldUnsetOr(q *elastic.BoolQuery, name string) *elastic.BoolQuery {
|
||||||
|
qUnset := elastic.NewBoolQuery().MustNot(elastic.NewExistsQuery(name))
|
||||||
|
qSet := elastic.NewBoolQuery().Must(elastic.NewExistsQuery(name)).Must(q)
|
||||||
|
return elastic.NewBoolQuery().Should(qUnset, qSet)
|
||||||
|
}
|
||||||
|
|
||||||
// Search /*
|
// Search /*
|
||||||
// Search logic is as follows:
|
// Search logic is as follows:
|
||||||
// 1) Setup query with params given
|
// 1) Setup query with params given
|
||||||
|
@ -673,7 +682,8 @@ func (s *Server) setupEsQuery(
|
||||||
q = AddRangeField(q, in.CreationHeight, "creation_height")
|
q = AddRangeField(q, in.CreationHeight, "creation_height")
|
||||||
q = AddRangeField(q, in.ActivationHeight, "activation_height")
|
q = AddRangeField(q, in.ActivationHeight, "activation_height")
|
||||||
q = AddRangeField(q, in.ExpirationHeight, "expiration_height")
|
q = AddRangeField(q, in.ExpirationHeight, "expiration_height")
|
||||||
q = RoundUpReleaseTime(q, in.ReleaseTime, "release_time")
|
qReleaseTime := RoundUpReleaseTime(elastic.NewBoolQuery(), in.ReleaseTime, "release_time")
|
||||||
|
q = q.Must(FieldUnsetOr(qReleaseTime, "release_time"))
|
||||||
q = AddRangeField(q, in.RepostCount, "repost_count")
|
q = AddRangeField(q, in.RepostCount, "repost_count")
|
||||||
q = AddRangeField(q, in.FeeAmount, "fee_amount")
|
q = AddRangeField(q, in.FeeAmount, "fee_amount")
|
||||||
q = AddRangeField(q, in.Duration, "duration")
|
q = AddRangeField(q, in.Duration, "duration")
|
||||||
|
|
Loading…
Reference in a new issue