github.com/weaviate/weaviate@v1.24.6/usecases/schema/remove_duplicate_props.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package schema
    13  
    14  import (
    15  	"strings"
    16  
    17  	"github.com/sirupsen/logrus"
    18  	"github.com/weaviate/weaviate/entities/models"
    19  )
    20  
    21  func (m *Manager) deduplicateProps(props []*models.Property,
    22  	className string,
    23  ) []*models.Property {
    24  	seen := map[string]struct{}{}
    25  	i := 0
    26  	for j, prop := range props {
    27  		name := strings.ToLower(prop.Name)
    28  		if _, ok := seen[name]; ok {
    29  			m.logger.WithFields(logrus.Fields{
    30  				"action": "startup_repair_schema",
    31  				"prop":   prop.Name,
    32  				"class":  className,
    33  			}).Warningf("removing duplicate property %s", prop.Name)
    34  			continue
    35  		}
    36  		if i != j {
    37  			props[i] = prop
    38  		}
    39  		seen[name] = struct{}{}
    40  		i++
    41  	}
    42  
    43  	return props[:i]
    44  }