Skip to content

Commit 6cc7386

Browse files
committed
Merge branch 'main' into lunny/refactor-issue
2 parents cf6500a + 6a4eb12 commit 6cc7386

File tree

20 files changed

+1978
-99
lines changed

20 files changed

+1978
-99
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ TEST_PGSQL_DBNAME ?= testgitea
179179
TEST_PGSQL_USERNAME ?= postgres
180180
TEST_PGSQL_PASSWORD ?= postgres
181181
TEST_PGSQL_SCHEMA ?= gtestschema
182+
TEST_MINIO_ENDPOINT ?= minio:9000
182183
TEST_MSSQL_HOST ?= mssql:1433
183184
TEST_MSSQL_DBNAME ?= gitea
184185
TEST_MSSQL_USERNAME ?= sa
@@ -574,6 +575,7 @@ generate-ini-pgsql:
574575
-e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
575576
-e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
576577
-e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
578+
-e 's|{{TEST_MINIO_ENDPOINT}}|${TEST_MINIO_ENDPOINT}|g' \
577579
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
578580
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
579581
-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \

models/admin/task.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,6 @@ func GetMigratingTask(ctx context.Context, repoID int64) (*Task, error) {
179179
return &task, nil
180180
}
181181

182-
// GetMigratingTaskByID returns the migrating task by repo's id
183-
func GetMigratingTaskByID(ctx context.Context, id, doerID int64) (*Task, *migration.MigrateOptions, error) {
184-
task := Task{
185-
ID: id,
186-
DoerID: doerID,
187-
Type: structs.TaskTypeMigrateRepo,
188-
}
189-
has, err := db.GetEngine(ctx).Get(&task)
190-
if err != nil {
191-
return nil, nil, err
192-
} else if !has {
193-
return nil, nil, ErrTaskDoesNotExist{id, 0, task.Type}
194-
}
195-
196-
var opts migration.MigrateOptions
197-
if err := json.Unmarshal([]byte(task.PayloadContent), &opts); err != nil {
198-
return nil, nil, err
199-
}
200-
return &task, &opts, nil
201-
}
202-
203182
// CreateTask creates a task on database
204183
func CreateTask(ctx context.Context, task *Task) error {
205184
return db.Insert(ctx, task)

models/user/search.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,19 @@ func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) *xorm.Sess
6565
builder.Like{"LOWER(full_name)", lowerKeyword},
6666
)
6767
if opts.SearchByEmail {
68-
keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
68+
var emailCond builder.Cond
69+
emailCond = builder.Like{"LOWER(email)", lowerKeyword}
70+
if opts.Actor == nil {
71+
emailCond = emailCond.And(builder.Eq{"keep_email_private": false})
72+
} else if !opts.Actor.IsAdmin {
73+
emailCond = emailCond.And(
74+
builder.Or(
75+
builder.Eq{"keep_email_private": false},
76+
builder.Eq{"id": opts.Actor.ID},
77+
),
78+
)
79+
}
80+
keywordCond = keywordCond.Or(emailCond)
6981
}
7082

7183
cond = cond.And(keywordCond)

modules/indexer/code/elasticsearch/elasticsearch.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
2121
inner_elasticsearch "code.gitea.io/gitea/modules/indexer/internal/elasticsearch"
2222
"code.gitea.io/gitea/modules/json"
23+
"code.gitea.io/gitea/modules/log"
2324
"code.gitea.io/gitea/modules/setting"
2425
"code.gitea.io/gitea/modules/timeutil"
2526
"code.gitea.io/gitea/modules/typesniffer"
@@ -197,8 +198,33 @@ func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha st
197198
return nil
198199
}
199200

200-
// Delete deletes indexes by ids
201+
// Delete entries by repoId
201202
func (b *Indexer) Delete(ctx context.Context, repoID int64) error {
203+
if err := b.doDelete(ctx, repoID); err != nil {
204+
// Maybe there is a conflict during the delete operation, so we should retry after a refresh
205+
log.Warn("Deletion of entries of repo %v within index %v was erroneus. Trying to refresh index before trying again", repoID, b.inner.VersionedIndexName(), err)
206+
if err := b.refreshIndex(ctx); err != nil {
207+
return err
208+
}
209+
if err := b.doDelete(ctx, repoID); err != nil {
210+
log.Error("Could not delete entries of repo %v within index %v", repoID, b.inner.VersionedIndexName())
211+
return err
212+
}
213+
}
214+
return nil
215+
}
216+
217+
func (b *Indexer) refreshIndex(ctx context.Context) error {
218+
if _, err := b.inner.Client.Refresh(b.inner.VersionedIndexName()).Do(ctx); err != nil {
219+
log.Error("Error while trying to refresh index %v", b.inner.VersionedIndexName(), err)
220+
return err
221+
}
222+
223+
return nil
224+
}
225+
226+
// Delete entries by repoId
227+
func (b *Indexer) doDelete(ctx context.Context, repoID int64) error {
202228
_, err := b.inner.Client.DeleteByQuery(b.inner.VersionedIndexName()).
203229
Query(elastic.NewTermsQuery("repo_id", repoID)).
204230
Do(ctx)

0 commit comments

Comments
 (0)