Skip to content

Commit

Permalink
Merge pull request #1513 from p-l-/fix-index-migration
Browse files Browse the repository at this point in the history
DB/Mongo: fix index migrations & .explain()
  • Loading branch information
p-l- committed May 5, 2023
2 parents ff7b3b3 + 9d2af5d commit 5f87772
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ivre/db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4240,7 +4240,7 @@ class MongoDBNmap(MongoDBActive, DBNmap):
("tags.value", pymongo.ASCENDING),
("tags.info", pymongo.ASCENDING),
],
{"sparse": True},
{},
),
],
)
Expand Down Expand Up @@ -4560,8 +4560,8 @@ class MongoDBPassive(MongoDB, DBPassive):
],
{},
),
([("infos.issuer", pymongo.ASCENDING)], {"sparse": True}),
([("infos.subject", pymongo.ASCENDING)], {"sparse": True}),
([("infos.issuer", pymongo.ASCENDING)], {}),
([("infos.subject", pymongo.ASCENDING)], {}),
],
"ensure": [
(
Expand Down
9 changes: 8 additions & 1 deletion ivre/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
USE_PIL = False
else:
USE_PIL = True
try:
from bson.regex import Regex as BsonRegex
except ImportError:
USE_BSON = False
else:
USE_BSON = True


from ivre import VERSION, config
Expand Down Expand Up @@ -809,7 +815,8 @@ def open_file(fname: str) -> FileOpener:

def serialize(obj: Any) -> str:
"""Return a JSON-compatible representation for `obj`"""
if isinstance(obj, REGEXP_T):
regexp_types = (REGEXP_T, BsonRegex) if USE_BSON else REGEXP_T
if isinstance(obj, regexp_types): # type: ignore
return "/%s/%s" % (
obj.pattern,
"".join(x.lower() for x in "ILMSXU" if getattr(re, x) & obj.flags),
Expand Down

0 comments on commit 5f87772

Please sign in to comment.