2019-01-17 17:23:22 +03:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 21:20:29 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-01-17 17:23:22 +03:00
|
|
|
|
|
|
|
package indexer
|
|
|
|
|
|
|
|
import (
|
2022-11-19 11:12:33 +03:00
|
|
|
"context"
|
|
|
|
|
2022-06-13 12:37:59 +03:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-12-10 04:27:50 +03:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-24 12:49:20 +03:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2019-12-08 22:15:35 +03:00
|
|
|
code_indexer "code.gitea.io/gitea/modules/indexer/code"
|
2019-02-21 03:54:05 +03:00
|
|
|
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
|
2020-02-11 12:34:17 +03:00
|
|
|
stats_indexer "code.gitea.io/gitea/modules/indexer/stats"
|
2019-02-19 17:39:39 +03:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2020-01-10 12:34:21 +03:00
|
|
|
"code.gitea.io/gitea/modules/repository"
|
2019-12-08 22:15:35 +03:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2023-09-05 21:37:47 +03:00
|
|
|
notify_service "code.gitea.io/gitea/services/notify"
|
2019-01-17 17:23:22 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type indexerNotifier struct {
|
2023-09-05 21:37:47 +03:00
|
|
|
notify_service.NullNotifier
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
var _ notify_service.Notifier = &indexerNotifier{}
|
2019-01-17 17:23:22 +03:00
|
|
|
|
|
|
|
// NewNotifier create a new indexerNotifier notifier
|
2023-09-05 21:37:47 +03:00
|
|
|
func NewNotifier() notify_service.Notifier {
|
2019-01-17 17:23:22 +03:00
|
|
|
return &indexerNotifier{}
|
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) AdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
|
|
|
r.MigrateRepository(ctx, doer, u, repo)
|
2023-06-26 09:59:15 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
2022-06-13 12:37:59 +03:00
|
|
|
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
2022-02-23 23:16:07 +03:00
|
|
|
) {
|
2023-08-16 12:36:05 +03:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
Refactor and enhance issue indexer to support both searching, filtering and paging (#26012)
Fix #24662.
Replace #24822 and #25708 (although it has been merged)
## Background
In the past, Gitea supported issue searching with a keyword and
conditions in a less efficient way. It worked by searching for issues
with the keyword and obtaining limited IDs (as it is heavy to get all)
on the indexer (bleve/elasticsearch/meilisearch), and then querying with
conditions on the database to find a subset of the found IDs. This is
why the results could be incomplete.
To solve this issue, we need to store all fields that could be used as
conditions in the indexer and support both keyword and additional
conditions when searching with the indexer.
## Major changes
- Redefine `IndexerData` to include all fields that could be used as
filter conditions.
- Refactor `Search(ctx context.Context, kw string, repoIDs []int64,
limit, start int, state string)` to `Search(ctx context.Context, options
*SearchOptions)`, so it supports more conditions now.
- Change the data type stored in `issueIndexerQueue`. Use
`IndexerMetadata` instead of `IndexerData` in case the data has been
updated while it is in the queue. This also reduces the storage size of
the queue.
- Enhance searching with Bleve/Elasticsearch/Meilisearch, make them
fully support `SearchOptions`. Also, update the data versions.
- Keep most logic of database indexer, but remove
`issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is
the entry point to search issues.
- Start a Meilisearch instance to test it in unit tests.
- Add unit tests with almost full coverage to test
Bleve/Elasticsearch/Meilisearch indexer.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-07-31 09:28:53 +03:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
2023-08-16 12:36:05 +03:00
|
|
|
if err := pr.LoadIssue(ctx); err != nil {
|
|
|
|
log.Error("LoadIssue: %v", err)
|
|
|
|
return
|
|
|
|
}
|
Refactor and enhance issue indexer to support both searching, filtering and paging (#26012)
Fix #24662.
Replace #24822 and #25708 (although it has been merged)
## Background
In the past, Gitea supported issue searching with a keyword and
conditions in a less efficient way. It worked by searching for issues
with the keyword and obtaining limited IDs (as it is heavy to get all)
on the indexer (bleve/elasticsearch/meilisearch), and then querying with
conditions on the database to find a subset of the found IDs. This is
why the results could be incomplete.
To solve this issue, we need to store all fields that could be used as
conditions in the indexer and support both keyword and additional
conditions when searching with the indexer.
## Major changes
- Redefine `IndexerData` to include all fields that could be used as
filter conditions.
- Refactor `Search(ctx context.Context, kw string, repoIDs []int64,
limit, start int, state string)` to `Search(ctx context.Context, options
*SearchOptions)`, so it supports more conditions now.
- Change the data type stored in `issueIndexerQueue`. Use
`IndexerMetadata` instead of `IndexerData` in case the data has been
updated while it is in the queue. This also reduces the storage size of
the queue.
- Enhance searching with Bleve/Elasticsearch/Meilisearch, make them
fully support `SearchOptions`. Also, update the data versions.
- Keep most logic of database indexer, but remove
`issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is
the entry point to search issues.
- Start a Meilisearch instance to test it in unit tests.
- Add unit tests with almost full coverage to test
Bleve/Elasticsearch/Meilisearch indexer.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-07-31 09:28:53 +03:00
|
|
|
issue_indexer.UpdateIssueIndexer(pr.Issue.ID)
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
|
2023-08-16 12:36:05 +03:00
|
|
|
if err := c.LoadIssue(ctx); err != nil {
|
|
|
|
log.Error("LoadIssue: %v", err)
|
|
|
|
return
|
|
|
|
}
|
Refactor and enhance issue indexer to support both searching, filtering and paging (#26012)
Fix #24662.
Replace #24822 and #25708 (although it has been merged)
## Background
In the past, Gitea supported issue searching with a keyword and
conditions in a less efficient way. It worked by searching for issues
with the keyword and obtaining limited IDs (as it is heavy to get all)
on the indexer (bleve/elasticsearch/meilisearch), and then querying with
conditions on the database to find a subset of the found IDs. This is
why the results could be incomplete.
To solve this issue, we need to store all fields that could be used as
conditions in the indexer and support both keyword and additional
conditions when searching with the indexer.
## Major changes
- Redefine `IndexerData` to include all fields that could be used as
filter conditions.
- Refactor `Search(ctx context.Context, kw string, repoIDs []int64,
limit, start int, state string)` to `Search(ctx context.Context, options
*SearchOptions)`, so it supports more conditions now.
- Change the data type stored in `issueIndexerQueue`. Use
`IndexerMetadata` instead of `IndexerData` in case the data has been
updated while it is in the queue. This also reduces the storage size of
the queue.
- Enhance searching with Bleve/Elasticsearch/Meilisearch, make them
fully support `SearchOptions`. Also, update the data versions.
- Keep most logic of database indexer, but remove
`issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is
the entry point to search issues.
- Start a Meilisearch instance to test it in unit tests.
- Add unit tests with almost full coverage to test
Bleve/Elasticsearch/Meilisearch indexer.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-07-31 09:28:53 +03:00
|
|
|
issue_indexer.UpdateIssueIndexer(c.Issue.ID)
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
|
2023-08-16 12:36:05 +03:00
|
|
|
if err := comment.LoadIssue(ctx); err != nil {
|
|
|
|
log.Error("LoadIssue: %v", err)
|
|
|
|
return
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
2023-08-16 12:36:05 +03:00
|
|
|
issue_indexer.UpdateIssueIndexer(comment.Issue.ID)
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
|
Refactor and enhance issue indexer to support both searching, filtering and paging (#26012)
Fix #24662.
Replace #24822 and #25708 (although it has been merged)
## Background
In the past, Gitea supported issue searching with a keyword and
conditions in a less efficient way. It worked by searching for issues
with the keyword and obtaining limited IDs (as it is heavy to get all)
on the indexer (bleve/elasticsearch/meilisearch), and then querying with
conditions on the database to find a subset of the found IDs. This is
why the results could be incomplete.
To solve this issue, we need to store all fields that could be used as
conditions in the indexer and support both keyword and additional
conditions when searching with the indexer.
## Major changes
- Redefine `IndexerData` to include all fields that could be used as
filter conditions.
- Refactor `Search(ctx context.Context, kw string, repoIDs []int64,
limit, start int, state string)` to `Search(ctx context.Context, options
*SearchOptions)`, so it supports more conditions now.
- Change the data type stored in `issueIndexerQueue`. Use
`IndexerMetadata` instead of `IndexerData` in case the data has been
updated while it is in the queue. This also reduces the storage size of
the queue.
- Enhance searching with Bleve/Elasticsearch/Meilisearch, make them
fully support `SearchOptions`. Also, update the data versions.
- Keep most logic of database indexer, but remove
`issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is
the entry point to search issues.
- Start a Meilisearch instance to test it in unit tests.
- Add unit tests with almost full coverage to test
Bleve/Elasticsearch/Meilisearch indexer.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-07-31 09:28:53 +03:00
|
|
|
issue_indexer.DeleteRepoIssueIndexer(ctx, repo.ID)
|
2019-12-08 22:15:35 +03:00
|
|
|
if setting.Indexer.RepoIndexerEnabled {
|
2021-11-02 06:14:24 +03:00
|
|
|
code_indexer.UpdateRepoIndexer(repo)
|
2019-12-08 22:15:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
Refactor and enhance issue indexer to support both searching, filtering and paging (#26012)
Fix #24662.
Replace #24822 and #25708 (although it has been merged)
## Background
In the past, Gitea supported issue searching with a keyword and
conditions in a less efficient way. It worked by searching for issues
with the keyword and obtaining limited IDs (as it is heavy to get all)
on the indexer (bleve/elasticsearch/meilisearch), and then querying with
conditions on the database to find a subset of the found IDs. This is
why the results could be incomplete.
To solve this issue, we need to store all fields that could be used as
conditions in the indexer and support both keyword and additional
conditions when searching with the indexer.
## Major changes
- Redefine `IndexerData` to include all fields that could be used as
filter conditions.
- Refactor `Search(ctx context.Context, kw string, repoIDs []int64,
limit, start int, state string)` to `Search(ctx context.Context, options
*SearchOptions)`, so it supports more conditions now.
- Change the data type stored in `issueIndexerQueue`. Use
`IndexerMetadata` instead of `IndexerData` in case the data has been
updated while it is in the queue. This also reduces the storage size of
the queue.
- Enhance searching with Bleve/Elasticsearch/Meilisearch, make them
fully support `SearchOptions`. Also, update the data versions.
- Keep most logic of database indexer, but remove
`issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is
the entry point to search issues.
- Start a Meilisearch instance to test it in unit tests.
- Add unit tests with almost full coverage to test
Bleve/Elasticsearch/Meilisearch indexer.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-07-31 09:28:53 +03:00
|
|
|
issue_indexer.UpdateRepoIndexer(ctx, repo.ID)
|
2019-12-08 22:15:35 +03:00
|
|
|
if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty {
|
|
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
|
|
}
|
2020-02-11 12:34:17 +03:00
|
|
|
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
|
|
|
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
|
|
|
}
|
2019-12-08 22:15:35 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
2023-05-26 04:04:48 +03:00
|
|
|
if !opts.RefFullName.IsBranch() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName.BranchName() == repo.DefaultBranch {
|
2019-12-08 22:15:35 +03:00
|
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
|
|
}
|
2020-02-11 12:34:17 +03:00
|
|
|
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
|
|
|
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
|
|
|
}
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
2023-05-26 04:04:48 +03:00
|
|
|
if !opts.RefFullName.IsBranch() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName.BranchName() == repo.DefaultBranch {
|
2020-05-08 17:58:40 +03:00
|
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
|
|
}
|
|
|
|
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
|
|
|
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
|
Refactor and enhance issue indexer to support both searching, filtering and paging (#26012)
Fix #24662.
Replace #24822 and #25708 (although it has been merged)
## Background
In the past, Gitea supported issue searching with a keyword and
conditions in a less efficient way. It worked by searching for issues
with the keyword and obtaining limited IDs (as it is heavy to get all)
on the indexer (bleve/elasticsearch/meilisearch), and then querying with
conditions on the database to find a subset of the found IDs. This is
why the results could be incomplete.
To solve this issue, we need to store all fields that could be used as
conditions in the indexer and support both keyword and additional
conditions when searching with the indexer.
## Major changes
- Redefine `IndexerData` to include all fields that could be used as
filter conditions.
- Refactor `Search(ctx context.Context, kw string, repoIDs []int64,
limit, start int, state string)` to `Search(ctx context.Context, options
*SearchOptions)`, so it supports more conditions now.
- Change the data type stored in `issueIndexerQueue`. Use
`IndexerMetadata` instead of `IndexerData` in case the data has been
updated while it is in the queue. This also reduces the storage size of
the queue.
- Enhance searching with Bleve/Elasticsearch/Meilisearch, make them
fully support `SearchOptions`. Also, update the data versions.
- Keep most logic of database indexer, but remove
`issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is
the entry point to search issues.
- Start a Meilisearch instance to test it in unit tests.
- Add unit tests with almost full coverage to test
Bleve/Elasticsearch/Meilisearch indexer.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-07-31 09:28:53 +03:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
Refactor and enhance issue indexer to support both searching, filtering and paging (#26012)
Fix #24662.
Replace #24822 and #25708 (although it has been merged)
## Background
In the past, Gitea supported issue searching with a keyword and
conditions in a less efficient way. It worked by searching for issues
with the keyword and obtaining limited IDs (as it is heavy to get all)
on the indexer (bleve/elasticsearch/meilisearch), and then querying with
conditions on the database to find a subset of the found IDs. This is
why the results could be incomplete.
To solve this issue, we need to store all fields that could be used as
conditions in the indexer and support both keyword and additional
conditions when searching with the indexer.
## Major changes
- Redefine `IndexerData` to include all fields that could be used as
filter conditions.
- Refactor `Search(ctx context.Context, kw string, repoIDs []int64,
limit, start int, state string)` to `Search(ctx context.Context, options
*SearchOptions)`, so it supports more conditions now.
- Change the data type stored in `issueIndexerQueue`. Use
`IndexerMetadata` instead of `IndexerData` in case the data has been
updated while it is in the queue. This also reduces the storage size of
the queue.
- Enhance searching with Bleve/Elasticsearch/Meilisearch, make them
fully support `SearchOptions`. Also, update the data versions.
- Keep most logic of database indexer, but remove
`issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is
the entry point to search issues.
- Start a Meilisearch instance to test it in unit tests.
- Add unit tests with almost full coverage to test
Bleve/Elasticsearch/Meilisearch indexer.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-07-31 09:28:53 +03:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2019-01-17 17:23:22 +03:00
|
|
|
}
|
2020-09-08 19:29:51 +03:00
|
|
|
|
2023-09-05 21:37:47 +03:00
|
|
|
func (r *indexerNotifier) IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) {
|
Refactor and enhance issue indexer to support both searching, filtering and paging (#26012)
Fix #24662.
Replace #24822 and #25708 (although it has been merged)
## Background
In the past, Gitea supported issue searching with a keyword and
conditions in a less efficient way. It worked by searching for issues
with the keyword and obtaining limited IDs (as it is heavy to get all)
on the indexer (bleve/elasticsearch/meilisearch), and then querying with
conditions on the database to find a subset of the found IDs. This is
why the results could be incomplete.
To solve this issue, we need to store all fields that could be used as
conditions in the indexer and support both keyword and additional
conditions when searching with the indexer.
## Major changes
- Redefine `IndexerData` to include all fields that could be used as
filter conditions.
- Refactor `Search(ctx context.Context, kw string, repoIDs []int64,
limit, start int, state string)` to `Search(ctx context.Context, options
*SearchOptions)`, so it supports more conditions now.
- Change the data type stored in `issueIndexerQueue`. Use
`IndexerMetadata` instead of `IndexerData` in case the data has been
updated while it is in the queue. This also reduces the storage size of
the queue.
- Enhance searching with Bleve/Elasticsearch/Meilisearch, make them
fully support `SearchOptions`. Also, update the data versions.
- Keep most logic of database indexer, but remove
`issues.SearchIssueIDsByKeyword` in `models` to avoid confusion where is
the entry point to search issues.
- Start a Meilisearch instance to test it in unit tests.
- Add unit tests with almost full coverage to test
Bleve/Elasticsearch/Meilisearch indexer.
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-07-31 09:28:53 +03:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2020-09-08 19:29:51 +03:00
|
|
|
}
|