Batch fix
This commit is contained in:
parent
53a17bbd24
commit
369ddf76a8
14 changed files with 75 additions and 14 deletions
|
@ -64,6 +64,10 @@ func CommitRepoAction(userId int64, userName string,
|
|||
watches = append(watches, Watch{UserId: userId})
|
||||
|
||||
for i := range watches {
|
||||
if userId == watches[i].UserId && i > 0 {
|
||||
continue // Do not add twice in case author watches his/her repository.
|
||||
}
|
||||
|
||||
_, err = orm.InsertOne(&Action{
|
||||
UserId: watches[i].UserId,
|
||||
ActUserId: userId,
|
||||
|
|
|
@ -7,6 +7,7 @@ package models
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
|
@ -23,6 +24,7 @@ func setEngine() {
|
|||
dbName := base.Cfg.MustValue("database", "NAME")
|
||||
dbUser := base.Cfg.MustValue("database", "USER")
|
||||
dbPwd := base.Cfg.MustValue("database", "PASSWD")
|
||||
dbPath := base.Cfg.MustValue("database", "PATH", "data/gogs.db")
|
||||
sslMode := base.Cfg.MustValue("database", "SSL_MODE")
|
||||
|
||||
var err error
|
||||
|
@ -33,6 +35,9 @@ func setEngine() {
|
|||
case "postgres":
|
||||
orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
|
||||
dbUser, dbPwd, dbName, sslMode))
|
||||
case "sqlite3":
|
||||
os.MkdirAll(path.Dir(dbPath), os.ModePerm)
|
||||
orm, err = xorm.NewEngine("sqlite3", dbPath)
|
||||
default:
|
||||
fmt.Printf("Unknown database type: %s\n", dbType)
|
||||
os.Exit(2)
|
||||
|
|
|
@ -323,11 +323,33 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
|
|||
return nil
|
||||
}
|
||||
|
||||
// UserRepo reporesents a repository with user name.
|
||||
type UserRepo struct {
|
||||
*Repository
|
||||
UserName string
|
||||
}
|
||||
|
||||
// GetRepos returns given number of repository objects with offset.
|
||||
func GetRepos(num, offset int) ([]Repository, error) {
|
||||
func GetRepos(num, offset int) ([]UserRepo, error) {
|
||||
repos := make([]Repository, 0, num)
|
||||
err := orm.Limit(num, offset).Asc("id").Find(&repos)
|
||||
return repos, err
|
||||
if err := orm.Limit(num, offset).Asc("id").Find(&repos); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
urepos := make([]UserRepo, len(repos))
|
||||
for i := range repos {
|
||||
urepos[i].Repository = &repos[i]
|
||||
u := new(User)
|
||||
has, err := orm.Id(urepos[i].Repository.OwnerId).Get(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrUserNotExist
|
||||
}
|
||||
urepos[i].UserName = u.Name
|
||||
}
|
||||
|
||||
return urepos, nil
|
||||
}
|
||||
|
||||
func RepoPath(userName, repoName string) string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue