MCPcopy Create free account
hub / github.com/MongoEngine/mongoengine / _build_index_specs

Method _build_index_specs

mongoengine/base/document.py:849–879  ·  view source on GitHub ↗

Generate and merge the full index specs.

(cls, meta_indexes)

Source from the content-addressed store, hash-verified

847
848 @classmethod
849 def _build_index_specs(cls, meta_indexes):
850 """Generate and merge the full index specs."""
851 geo_indices = cls._geo_indices()
852 unique_indices = cls._unique_with_indexes()
853 index_specs = [cls._build_index_spec(spec) for spec in meta_indexes]
854
855 def merge_index_specs(index_specs, indices):
856 """Helper method for merging index specs."""
857 if not indices:
858 return index_specs
859
860 # Create a map of index fields to index spec. We're converting
861 # the fields from a list to a tuple so that it's hashable.
862 spec_fields = {tuple(index["fields"]): index for index in index_specs}
863
864 # For each new index, if there's an existing index with the same
865 # fields list, update the existing spec with all data from the
866 # new spec.
867 for new_index in indices:
868 candidate = spec_fields.get(tuple(new_index["fields"]))
869 if candidate is None:
870 index_specs.append(new_index)
871 else:
872 candidate.update(new_index)
873
874 return index_specs
875
876 # Merge geo indexes and unique_with indexes into the meta index specs.
877 index_specs = merge_index_specs(index_specs, geo_indices)
878 index_specs = merge_index_specs(index_specs, unique_indices)
879 return index_specs
880
881 @classmethod
882 def _build_index_spec(cls, spec):

Callers 1

__new__Method · 0.80

Calls 3

_geo_indicesMethod · 0.80
_unique_with_indexesMethod · 0.80
_build_index_specMethod · 0.80

Tested by

no test coverage detected