Skip to content

Instantly share code, notes, and snippets.

@dhoss
Created August 26, 2015 19:41
Show Gist options
  • Save dhoss/6ad337e5ae7683aad991 to your computer and use it in GitHub Desktop.
Save dhoss/6ad337e5ae7683aad991 to your computer and use it in GitHub Desktop.
returning Object?
def commitsFor(project: String, page: Option[Int] = None, limit: Option[Int] = None) = { //: Future[List[scala.collection.immutable.Map[String, List[Commit]]]] = {
// grab repos for a project name. need to make this async.
// need to return project from API if no projects exist, then queue up a db population
// need to account for nonexistent projects as well
Logger.info("DAL commitsFor " + project)
// make me non-blocking
val projectId = Await.result(db.run(Projects.filter(_.name === project).map(_.id).result), 2 seconds).headOption
val repoQuery = Repositories.filter(_.project === projectId).map(_.name)
val commitsQuery = Commits.filter(_.repository in repoQuery).take(50).result
Logger.debug("SQL " + commitsQuery.statements.head)
val commits = db.run(commitsQuery)
Logger.debug("COMMITS " + Await.result(commits, Duration.Inf))
Logger.debug("COMMIT OBJ " + dump(commits))
Logger.debug("Abbout to hit flatMap")
commits.flatMap {
case Nil => Future.successful(updateDbAndReturnCommits(project, stashClient))
case commitsData => Future.successful(commits) // this is definitely being hit
}
}
def dump[T: Manifest](t: T) = "%s: %s".format(t, manifest[T])
"commitsFor() pagination" should {
"retrieve 100 rows by default" in new WithApplication
with RepositoryTable
with CommitTable
with ProjectTable
with WithDatabaseConfig
with DBCleanup
with DBFixtures {
import driver.api._
//create an instance of the table
val Projects = TableQuery[Projects]
val Repositories = TableQuery[Repositories]
val Commits = TableQuery[Commits]
val dal = new DAL()
val fixture = new Fixtures()
fixture.populate()
dal.commitsFor("blas").map( commit => println("COMMIT " + dump(commit)))
// Await.result(dal.commitsFor("blas"), Duration.Inf) must have length(be_<=(100))
}
[info] commitsFor() pagination should
[info] - play.api.libs.concurrent.ActorSystemProvider - Starting application default Akka system: application
[info] - application - Retrieving repos for mem
[info] - application - Retrieving repos for blas
[info] - application - Retrieving repos for cb
[info] - application - DAL commitsFor blas
[debug] - application - SQL select x2."id", x2."git_id", x2."message", x2."author", x2."email", x2."author_timestamp", x2."repository", x2."created_at", x2."updated_at" from (select x3."updated_at" as "updated_at", x3."git_id" as "git_id", x3."repository" as "repository", x3."email" as "email", x3."created_at" as "created_at", x3."message" as "message", x3."id" as "id", x3."author" as "author", x3."author_timestamp" as "author_timestamp" from "commit" x3 where x3."repository" in (select x4."name" from "repository" x4 where x4."project" = 223) limit 50) x2
[debug] - application - COMMITS Vector(Commit(1729,74e5140b53e9c8fcc42a295df7ebdda2bef32a10,aut,test,[email protected],Some(2015-08-26T13:35:27.914-06:00),aut,Some(2015-08-26T13:35:27.914-06:00),Some(2015-08-26T13:35:27.914-06:00)), Commit(1730,f3e83971c02f6bde0275759542a4633fdf96915d,blaster,test,[email protected],Some(2015-08-26T13:35:27.915-06:00),blaster,Some(2015-08-26T13:35:27.915-06:00),Some(2015-08-26T13:35:27.915-06:00)), Commit(1731,60353c7fbada4f5edcd84aa9514542043ef2024e,tomcat,test,[email protected],Some(2015-08-26T13:35:27.918-06:00),tomcat,Some(2015-08-26T13:35:27.918-06:00),Some(2015-08-26T13:35:27.918-06:00)))
[debug] - application - COMMIT OBJ scala.concurrent.impl.Promise$DefaultPromise@76b71050: scala.concurrent.Future[scala.collection.Seq[models.Commit]]
[debug] - application - Abbout to hit flatMap
COMMIT scala.concurrent.impl.Promise$DefaultPromise@76b71050: Object
[info] - play.api.libs.concurrent.ActorSystemProvider - Shutdown application default Akka system: application
[info] + retrieve 100 rows by default
[info] - play.api.libs.concurrent.ActorSystemProvider - Starting application default Akka system: application
[info] - application - Retrieving repos for mem
[info] - application - Retrieving repos for blas
[info] - application - Retrieving repos for cb
[info] - play.api.libs.concurrent.ActorSystemProvider - Shutdown application default Akka system: application
[info] + retrieve the correct page when specified
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment