Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move code indexer related code to a new package #9191

Merged
merged 9 commits into from
Dec 8, 2019
Merged
7 changes: 4 additions & 3 deletions integrations/repo_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"code.gitea.io/gitea/models"
code_indexer "code.gitea.io/gitea/modules/indexer/code"
"code.gitea.io/gitea/modules/setting"

"github.com/PuerkitoBio/goquery"
Expand All @@ -34,7 +35,7 @@ func TestSearchRepo(t *testing.T) {
repo, err := models.GetRepositoryByOwnerAndName("user2", "repo1")
assert.NoError(t, err)

executeIndexer(t, repo, models.UpdateRepoIndexer)
executeIndexer(t, repo, code_indexer.UpdateRepoIndexer)

testSearch(t, "/user2/repo1/search?q=Description&page=1", []string{"README.md"})

Expand All @@ -44,8 +45,8 @@ func TestSearchRepo(t *testing.T) {
repo, err = models.GetRepositoryByOwnerAndName("user2", "glob")
assert.NoError(t, err)

executeIndexer(t, repo, models.DeleteRepoFromIndexer)
executeIndexer(t, repo, models.UpdateRepoIndexer)
executeIndexer(t, repo, code_indexer.DeleteRepoFromIndexer)
executeIndexer(t, repo, code_indexer.UpdateRepoIndexer)

testSearch(t, "/user2/glob/search?q=loren&page=1", []string{"a.txt"})
testSearch(t, "/user2/glob/search?q=file3&page=1", []string{"x/b.txt"})
Expand Down
25 changes: 25 additions & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,28 @@ func MaxBatchInsertSize(bean interface{}) int {
func Count(bean interface{}) (int64, error) {
return x.Count(bean)
}

// IsTableNotEmpty returns true if table has at least one record
func IsTableNotEmpty(tableName string) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also be changed to beanOrTableName interface{}?

return x.Table(tableName).Exist()
}

// DeleteAllRecords will delete all the records of this table
func DeleteAllRecords(tableName string) error {
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
_, err := x.Exec(fmt.Sprintf("DELETE FROM %s", tableName))
return err
}

// GetMaxID will return max id of the table
func GetMaxID(beanOrTableName interface{}) (maxID int64, err error) {
_, err = x.Select("MAX(id)").Table(beanOrTableName).Get(&maxID)
return
}

// FindByMaxID filled results as the condition from database
func FindByMaxID(maxID int64, limit int, results interface{}) error {
return x.Where("id <= ?", maxID).
OrderBy("id DESC").
Limit(limit).
Find(results)
}
4 changes: 0 additions & 4 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1112,10 +1112,6 @@ func MigrateRepositoryGitData(doer, u *User, repo *Repository, opts api.MigrateR
repo, err = CleanUpMigrateInfo(repo)
}

if err != nil && !repo.IsEmpty {
UpdateRepoIndexer(repo)
}

return repo, err
}

Expand Down
Loading