Helper method for merging index specs.
(index_specs, indices)
| 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) |