mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
fix(issue-search): delete issue from indexer on DeleteIssue (#11585)
Previously, issues were deleted from the indexer only when the repository was deleted. Individually deleting issues would not remove them from the indexer. Instead, they were merely hidden due to their IDs being absent from the DB. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11585 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Shiny Nematoda <snematoda.751k2@aleeas.com> Co-committed-by: Shiny Nematoda <snematoda.751k2@aleeas.com>
This commit is contained in:
parent
cf51d3c888
commit
9e67037a3f
7 changed files with 73 additions and 1 deletions
|
|
@ -262,6 +262,19 @@ func DeleteRepoIssueIndexer(ctx context.Context, repoID int64) {
|
|||
}
|
||||
}
|
||||
|
||||
// DeleteIssueIndexer deletes a single issue by it's ID
|
||||
//
|
||||
// NOTE: This does not perform any DB validation.
|
||||
// Hence, the issueID does not need to be present in the DB.
|
||||
func DeleteIssueIndexer(ctx context.Context, issueID int64) {
|
||||
if err := pushIssueIndexerQueue(ctx, &IndexerMetadata{
|
||||
IDs: []int64{issueID},
|
||||
IsDelete: true,
|
||||
}); err != nil {
|
||||
log.Error("Unable to push deleted issue %d to issue indexer: %v", issueID, err)
|
||||
}
|
||||
}
|
||||
|
||||
// IsAvailable checks if issue indexer is available
|
||||
func IsAvailable(ctx context.Context) bool {
|
||||
return (*globalIndexer.Load()).Ping(ctx) == nil
|
||||
|
|
|
|||
|
|
@ -4,7 +4,11 @@
|
|||
package issues
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forgejo.org/models/db"
|
||||
"forgejo.org/models/issues"
|
||||
|
|
@ -12,6 +16,7 @@ import (
|
|||
"forgejo.org/modules/indexer/issues/internal"
|
||||
"forgejo.org/modules/optional"
|
||||
"forgejo.org/modules/setting"
|
||||
"forgejo.org/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -24,7 +29,7 @@ func TestMain(m *testing.M) {
|
|||
func TestDBSearchIssues(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
setting.Indexer.IssueType = "db"
|
||||
defer test.MockVariableValue(&setting.Indexer.IssueType, "db")()
|
||||
InitIssueIndexer(true)
|
||||
|
||||
t.Run("search issues with keyword", searchIssueWithKeyword)
|
||||
|
|
@ -414,3 +419,39 @@ func searchIssueWithPaginator(t *testing.T) {
|
|||
assert.Equal(t, test.expectedTotal, total)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBleveDeleteIssue(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
tmp := t.TempDir()
|
||||
defer test.MockVariableValue(&setting.Indexer.IssuePath, filepath.Join(tmp, "indexers/issues.bleve"))()
|
||||
defer test.MockVariableValue(&setting.Indexer.IssueType, "bleve")()
|
||||
InitIssueIndexer(false)
|
||||
|
||||
ctx := t.Context()
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues.Issue{ID: 1})
|
||||
UpdateIssueIndexer(ctx, issue.ID)
|
||||
|
||||
opts := &internal.SearchOptions{
|
||||
RepoIDs: []int64{issue.RepoID},
|
||||
}
|
||||
opts.WithKeyword(ctx, "first")
|
||||
|
||||
assert.Eventually(t, func() bool {
|
||||
ids, _, err := SearchIssues(ctx, opts)
|
||||
if err != nil && strings.Contains(err.Error(), "not ready") {
|
||||
return false
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, err)
|
||||
return slices.Contains(ids, issue.ID)
|
||||
}, time.Second*5, time.Millisecond*100, "failed to update issue")
|
||||
|
||||
DeleteIssueIndexer(ctx, issue.ID)
|
||||
assert.Eventually(t, func() bool {
|
||||
ids, _, err := SearchIssues(ctx, opts)
|
||||
assert.NoError(t, err)
|
||||
return !slices.Contains(ids, issue.ID)
|
||||
}, time.Second*5, time.Millisecond*100, "failed to delete issue")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue