2019-01-17 14:23:22 +00:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-01-17 14:23:22 +00:00
|
|
|
|
|
|
|
package indexer
|
|
|
|
|
|
|
|
import (
|
2022-11-19 08:12:33 +00:00
|
|
|
"context"
|
|
|
|
|
2022-06-13 09:37:59 +00:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-12-10 01:27:50 +00:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-24 09:49:20 +00:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2019-12-08 19:15:35 +00:00
|
|
|
code_indexer "code.gitea.io/gitea/modules/indexer/code"
|
2019-02-21 00:54:05 +00:00
|
|
|
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
|
2020-02-11 09:34:17 +00:00
|
|
|
stats_indexer "code.gitea.io/gitea/modules/indexer/stats"
|
2019-02-19 14:39:39 +00:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2020-01-10 09:34:21 +00:00
|
|
|
"code.gitea.io/gitea/modules/repository"
|
2019-12-08 19:15:35 +00:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2023-09-05 18:37:47 +00:00
|
|
|
notify_service "code.gitea.io/gitea/services/notify"
|
2019-01-17 14:23:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type indexerNotifier struct {
|
2023-09-05 18:37:47 +00:00
|
|
|
notify_service.NullNotifier
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00:00
|
|
|
var _ notify_service.Notifier = &indexerNotifier{}
|
2019-01-17 14:23:22 +00:00
|
|
|
|
|
|
|
// NewNotifier create a new indexerNotifier notifier
|
2023-09-05 18:37:47 +00:00
|
|
|
func NewNotifier() notify_service.Notifier {
|
2019-01-17 14:23:22 +00:00
|
|
|
return &indexerNotifier{}
|
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00: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 06:59:15 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00:00
|
|
|
func (r *indexerNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
2022-06-13 09:37:59 +00:00
|
|
|
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
2022-02-23 20:16:07 +00:00
|
|
|
) {
|
2023-08-16 09:36:05 +00:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00: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 06:28:53 +00:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00:00
|
|
|
func (r *indexerNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
2023-08-16 09:36:05 +00: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 06:28:53 +00:00
|
|
|
issue_indexer.UpdateIssueIndexer(pr.Issue.ID)
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00:00
|
|
|
func (r *indexerNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
|
2023-08-16 09:36:05 +00: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 06:28:53 +00:00
|
|
|
issue_indexer.UpdateIssueIndexer(c.Issue.ID)
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00:00
|
|
|
func (r *indexerNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
|
2023-08-16 09:36:05 +00:00
|
|
|
if err := comment.LoadIssue(ctx); err != nil {
|
|
|
|
log.Error("LoadIssue: %v", err)
|
|
|
|
return
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
2023-08-16 09:36:05 +00:00
|
|
|
issue_indexer.UpdateIssueIndexer(comment.Issue.ID)
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00: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 06:28:53 +00:00
|
|
|
issue_indexer.DeleteRepoIssueIndexer(ctx, repo.ID)
|
2019-12-08 19:15:35 +00:00
|
|
|
if setting.Indexer.RepoIndexerEnabled {
|
2021-11-02 03:14:24 +00:00
|
|
|
code_indexer.UpdateRepoIndexer(repo)
|
2019-12-08 19:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00: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 06:28:53 +00:00
|
|
|
issue_indexer.UpdateRepoIndexer(ctx, repo.ID)
|
2019-12-08 19:15:35 +00:00
|
|
|
if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty {
|
|
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
|
|
}
|
2020-02-11 09:34:17 +00:00
|
|
|
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
|
|
|
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
|
|
|
}
|
2019-12-08 19:15:35 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00: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 01:04:48 +00:00
|
|
|
if !opts.RefFullName.IsBranch() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName.BranchName() == repo.DefaultBranch {
|
2019-12-08 19:15:35 +00:00
|
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
|
|
}
|
2020-02-11 09:34:17 +00:00
|
|
|
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
|
|
|
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
|
|
|
}
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00: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 01:04:48 +00:00
|
|
|
if !opts.RefFullName.IsBranch() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName.BranchName() == repo.DefaultBranch {
|
2020-05-08 14:58:40 +00: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-13 04:43:31 +00:00
|
|
|
func (r *indexerNotifier) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) {
|
|
|
|
if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty {
|
|
|
|
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 18:37:47 +00: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 06:28:53 +00:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00: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 06:28:53 +00:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2019-01-17 14:23:22 +00:00
|
|
|
}
|
2020-09-08 16:29:51 +00:00
|
|
|
|
2023-09-05 18:37:47 +00: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 06:28:53 +00:00
|
|
|
issue_indexer.UpdateIssueIndexer(issue.ID)
|
2020-09-08 16:29:51 +00:00
|
|
|
}
|