From fa8c657005e906d1fb6d038f9de2ced8cda53fcd Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 15 Oct 2015 22:25:07 -0700 Subject: [PATCH] some initial work on #1234 --- controller/pages.go | 70 ++++++++++++++++----------------------------- model/repo.go | 2 +- 2 files changed, 26 insertions(+), 46 deletions(-) diff --git a/controller/pages.go b/controller/pages.go index 506ecbfb3..392822c47 100644 --- a/controller/pages.go +++ b/controller/pages.go @@ -17,64 +17,44 @@ import ( func ShowIndex(c *gin.Context) { db := context.Database(c) + remote := context.Remote(c) user := session.User(c) if user == nil { - c.HTML(200, "login.html", gin.H{}) + c.Redirect(http.StatusSeeOther, "/login") return } - repos, err := model.GetRepoList(db, user) + var err error + var repos []*model.RepoLite + + // get the repository list from the cache + reposv, ok := c.Get("repos") + if ok { + repos = reposv.([]*model.RepoLite) + } else { + repos, err = remote.Repos(user) + if err != nil { + log.Errorf("Failure to get remote repositories for %s. %s.", + user.Login, err) + } else { + c.Set("repos", repos) + } + } + + // for each repository in the remote system we get + // the intersection of those repostiories in Drone + repos_, err := model.GetRepoListOf(db, repos) if err != nil { - log.Error(err) + log.Errorf("Failure to get repository list for %s. %s.", + user.Login, err) } c.HTML(200, "repos.html", gin.H{ "User": user, - "Repos": repos, + "Repos": repos_, }) } -// func ShowIndex(c *gin.Context) { -// db := context.Database(c) -// remote := context.Remote(c) -// user := session.User(c) -// if user == nil { -// c.Redirect(http.StatusSeeOther, "/login") -// return -// } - -// var err error -// var repos []*model.RepoLite - -// // get the repository list from the cache -// reposv, ok := c.Get("repos") -// if ok { -// repos = reposv.([]*model.RepoLite) -// } else { -// println("GETTING REMOTE REPOS") -// repos, err = remote.Repos(user) -// if err != nil { -// log.Errorf("Failure to get remote repositories for %s. %s.", -// user.Login, err) -// } else { -// c.Set("repos", repos) -// } -// } - -// // for each repository in the remote system we get -// // the intersection of those repostiories in Drone -// repos_, err := model.GetRepoListOf(db, repos) -// if err != nil { -// log.Errorf("Failure to get repository list for %s. %s.", -// user.Login, err) -// } - -// c.HTML(200, "repos.html", gin.H{ -// "User": user, -// "Repos": repos_, -// }) -// } - func ShowLogin(c *gin.Context) { c.HTML(200, "login.html", gin.H{"Error": c.Query("error")}) } diff --git a/model/repo.go b/model/repo.go index 9202fdfbb..1010453e1 100644 --- a/model/repo.go +++ b/model/repo.go @@ -69,7 +69,7 @@ func GetRepoListOf(db meddler.DB, listof []*RepoLite) ([]*Repo, error) { qs[i] = "?" in[i] = repo.FullName } - var stmt = "SELECT * FROM repos WHERE repo_full_name IN (" + strings.Join(qs, ",") + ")" + var stmt = "SELECT * FROM repos WHERE repo_full_name IN (" + strings.Join(qs, ",") + ") ORDER BY repo_name" var err = meddler.QueryAll(db, &repos, database.Rebind(stmt), in...) return repos, err }