gitea源码

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package meilisearch
  4. import (
  5. "fmt"
  6. "code.gitea.io/gitea/modules/log"
  7. )
  8. // VersionedIndexName returns the full index name with version
  9. func (i *Indexer) VersionedIndexName() string {
  10. return versionedIndexName(i.indexName, i.version)
  11. }
  12. func versionedIndexName(indexName string, version int) string {
  13. if version == 0 {
  14. // Old index name without version
  15. return indexName
  16. }
  17. // The format of the index name is <index_name>_v<version>, not <index_name>.v<version> like elasticsearch.
  18. // Because meilisearch does not support "." in index name, it should contain only alphanumeric characters, hyphens (-) and underscores (_).
  19. // See https://www.meilisearch.com/docs/learn/core_concepts/indexes#index-uid
  20. return fmt.Sprintf("%s_v%d", indexName, version)
  21. }
  22. func (i *Indexer) checkOldIndexes() {
  23. for v := 0; v < i.version; v++ {
  24. indexName := versionedIndexName(i.indexName, v)
  25. _, err := i.Client.GetIndex(indexName)
  26. if err == nil {
  27. log.Warn("Found older meilisearch index named %q, Gitea will keep the old NOT DELETED. You can delete the old version after the upgrade succeed.", indexName)
  28. }
  29. }
  30. }