Skip to content

Commit

Permalink
Merge pull request #140 from whdalsrnt/master
Browse files Browse the repository at this point in the history
refactor: change index policy
  • Loading branch information
whdalsrnt authored Jan 6, 2024
2 parents 38360c3 + 33c84bf commit f4010e5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/spaceone/core/model/mongo_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ def _load_default_meta(cls):
def _create_index(cls) -> None:
if cls.auto_create_index:
indexes = cls._meta.get("indexes", [])
unique_fields = cls._get_unique_fields()

if len(indexes) > 0 or len(unique_fields) > 0:
total_index_count = len(indexes) + len(unique_fields)

if len(indexes) > 0:
_LOGGER.debug(
f"Create MongoDB Indexes ({cls.__name__} Model: {len(indexes)} Indexes)"
f"Create MongoDB Indexes ({cls.__name__} Model: {total_index_count} Indexes)"
)

unique_fields = cls._get_unique_fields()

for unique_field in unique_fields:
try:
cls.create_index({"fields": unique_field, "unique": True})
Expand Down

0 comments on commit f4010e5

Please sign in to comment.