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:
Jonathan Moody 2022-08-03 12:19:25 -04:00 committed by GitHub
parent 8b4b27bdb9
commit 49e5d7b8c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View file

@ -446,20 +446,24 @@ func GetProdDB(name string, secondaryPath string) (*ReadOnlyDBColumnFamily, func
db, err := GetDBColumnFamilies(name, secondaryPath, cfNames)
cleanup := func() {
db.DB.Close()
cleanupFiles := func() {
err = os.RemoveAll(secondaryPath)
if err != nil {
log.Println(err)
}
}
db.Cleanup = cleanup
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.

View file

@ -208,6 +208,15 @@ func RoundUpReleaseTime(q *elastic.BoolQuery, rqs []*pb.RangeField, name string)
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 logic is as follows:
// 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.ActivationHeight, "activation_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.FeeAmount, "fee_amount")
q = AddRangeField(q, in.Duration, "duration")