Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.0.0
version = 3.0.1

style = defaultWithAlign
maxColumn = 100
Expand Down
8 changes: 4 additions & 4 deletions fetch-debug/src/main/scala/debug.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ object debug {
def firstRequest(r: Round): Option[Long] =
for {
aQuery <- r.queries.headOption
firstR = r.queries.foldLeft(aQuery.start)({ case (acc, q) =>
firstR = r.queries.foldLeft(aQuery.start) { case (acc, q) =>
acc min q.start
})
}
} yield firstR

def lastRequest(r: Round): Option[Long] =
for {
aQuery <- r.queries.headOption
lastR = r.queries.foldLeft(aQuery.end)({ case (acc, q) =>
lastR = r.queries.foldLeft(aQuery.end) { case (acc, q) =>
acc max q.end
})
}
} yield lastR

def showLog(log: Log): Document =
Expand Down
4 changes: 2 additions & 2 deletions fetch-examples/src/test/scala/GithubExample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ class GithubExample extends AnyWordSpec with Matchers {
case class Project(repo: Repo, contributors: List[Contributor], languages: List[Language])

def fetchProject[F[_]: Async](repo: Repo): Fetch[F, Project] =
(repoContributors(repo), repoLanguages(repo)).mapN({ case (contribs, langs) =>
(repoContributors(repo), repoLanguages(repo)).mapN { case (contribs, langs) =>
Project(repo = repo, contributors = contribs, languages = langs)
})
}

def fetchOrg[F[_]: Async](org: String) =
for {
Expand Down
8 changes: 4 additions & 4 deletions fetch-examples/src/test/scala/GraphQLExample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,19 @@ class GraphQLExample extends AnyWordSpec with Matchers {

object Parsers {
def queryParser: Parser[OrganizationQuery] =
rawParser.map({ case (o, n) =>
rawParser.map { case (o, n) =>
OrganizationQuery(
o,
n.map({ case (i, name, langs, colls) =>
n.map { case (i, name, langs, colls) =>
RepositoriesQuery(
i,
if (name) Some(()) else None,
if (langs) Some(LanguagesQuery()) else None,
if (colls) Some(CollaboratorsQuery()) else None
)
})
}
)
})
}

def rawParser: Parser[(String, Option[(Int, Boolean, Boolean, Boolean)])] =
for {
Expand Down
12 changes: 6 additions & 6 deletions fetch-examples/src/test/scala/JedisExample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,26 @@ object Binary {
): F[ByteArray] = {
byteOutputStream
.mproduct(outputStream(_))
.use({ case (byte, out) =>
.use { case (byte, out) =>
S.delay {
out.writeObject(obj)
out.flush()
byte.toByteArray
}
})
}
}

def deserialize[F[_], A](bin: ByteArray)(implicit
S: Sync[F]
): F[Option[A]] = {
byteInputStream(bin)
.mproduct(inputStream(_))
.use({ case (byte, in) =>
.use { case (byte, in) =>
S.delay {
val obj = in.readObject()
Try(obj.asInstanceOf[A]).toOption
}
})
}
}
}

Expand Down Expand Up @@ -159,9 +159,9 @@ case class RedisCache[F[_]: Sync](host: String) extends DataCache[F] {
M: Monad[F]
): F[DataCache[F]] =
for {
bin <- vs.traverse({ case (id, v) =>
bin <- vs.traverse { case (id, v) =>
Binary.serialize(v).tupleRight(cacheId(id, data))
})
}
_ <- Sync[F].delay(bulkSet(bin))
} yield this

Expand Down
4 changes: 2 additions & 2 deletions fetch/src/main/scala/cache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ object InMemoryCache {
InMemoryCache[F](Map.empty[(Data[Any, Any], DataSourceId), DataSourceResult])

def from[F[_]: Monad, I, A](results: ((Data[I, A], I), A)*): InMemoryCache[F] =
InMemoryCache[F](results.foldLeft(Map.empty[(Data[Any, Any], DataSourceId), DataSourceResult])({
InMemoryCache[F](results.foldLeft(Map.empty[(Data[Any, Any], DataSourceId), DataSourceResult]) {
case (acc, ((data, i), v)) =>
acc.updated(
(data.asInstanceOf[Data[Any, Any]], new DataSourceId(i)),
new DataSourceResult(v)
)
}))
})
}
8 changes: 4 additions & 4 deletions fetch/src/main/scala/fetch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ object `package` {
.get(dsId)
.fold(
(ds, blocked)
)({ case (d, req) =>
) { case (d, req) =>
(d, combineRequests(blocked, req))
})
}
acc.updated(dsId, combined)
}
)
Expand Down Expand Up @@ -601,9 +601,9 @@ object `package` {
requests <- FetchExecution.parallel(
NonEmptyList
.fromListUnsafe(blocked)
.map({ case (ds, req) =>
.map { case (ds, req) =>
runBlockedRequest(req, ds, cache, log)
})
}
)
performedRequests = requests.foldLeft(List.empty[Request])(_ ++ _)
_ <-
Expand Down
28 changes: 14 additions & 14 deletions fetch/src/test/scala/FetchBatchingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ class FetchBatchingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
result shouldEqual List(1, 2, 3, 4, 5)
log.rounds.size shouldEqual 1
totalFetched(log.rounds) shouldEqual 5
totalBatches(log.rounds) shouldEqual 3
}).unsafeToFuture()
}.unsafeToFuture()
}

"A large fetch to a datasource with a maximum batch size is split and executed in parallel" in {
Expand All @@ -123,12 +123,12 @@ class FetchBatchingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
result shouldEqual List(1, 2, 3, 4, 5)
log.rounds.size shouldEqual 1
totalFetched(log.rounds) shouldEqual 5
totalBatches(log.rounds) shouldEqual 3
}).unsafeToFuture()
}.unsafeToFuture()
}

"Fetches to datasources with a maximum batch size should be split and executed in parallel and sequentially when using productR" in {
Expand All @@ -138,12 +138,12 @@ class FetchBatchingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
result shouldEqual List(1, 2, 3, 4, 5)
log.rounds.size shouldEqual 1
totalFetched(log.rounds) shouldEqual 5 + 5
totalBatches(log.rounds) shouldEqual 3 + 3
}).unsafeToFuture()
}.unsafeToFuture()
}

"Fetches to datasources with a maximum batch size should be split and executed in parallel and sequentially when using productL" in {
Expand All @@ -153,12 +153,12 @@ class FetchBatchingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
result shouldEqual List(1, 2, 3, 4, 5)
log.rounds.size shouldEqual 1
totalFetched(log.rounds) shouldEqual 5 + 5
totalBatches(log.rounds) shouldEqual 3 + 3
}).unsafeToFuture()
}.unsafeToFuture()
}

"A large (many) fetch to a datasource with a maximum batch size is split and executed in sequence" in {
Expand All @@ -167,12 +167,12 @@ class FetchBatchingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
result shouldEqual List(1, 2, 3)
log.rounds.size shouldEqual 1
totalFetched(log.rounds) shouldEqual 3
totalBatches(log.rounds) shouldEqual 2
}).unsafeToFuture()
}.unsafeToFuture()
}

"A large (many) fetch to a datasource with a maximum batch size is split and executed in parallel" in {
Expand All @@ -181,12 +181,12 @@ class FetchBatchingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
result shouldEqual List(1, 2, 3)
log.rounds.size shouldEqual 1
totalFetched(log.rounds) shouldEqual 3
totalBatches(log.rounds) shouldEqual 2
}).unsafeToFuture()
}.unsafeToFuture()
}

"Very deep fetches don't overflow stack or heap" in {
Expand All @@ -203,8 +203,8 @@ class FetchBatchingTests extends FetchSpec {
ids.toList.traverse(fetchBatchedDataBigId[IO])
)

io.map({ case (log, result) =>
io.map { case (log, result) =>
result shouldEqual ids.map(_.toString)
}).unsafeToFuture()
}.unsafeToFuture()
}
}
32 changes: 16 additions & 16 deletions fetch/src/test/scala/FetchReportingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class FetchReportingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
log.rounds.size shouldEqual 0
}).unsafeToFuture()
}.unsafeToFuture()
}

"Single fetches are executed in one round" in {
Expand All @@ -40,9 +40,9 @@ class FetchReportingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch[IO])

io.map({ case (log, result) =>
io.map { case (log, result) =>
log.rounds.size shouldEqual 1
}).unsafeToFuture()
}.unsafeToFuture()
}

"Single fetches are executed in one round per binding in a for comprehension" in {
Expand All @@ -54,9 +54,9 @@ class FetchReportingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
log.rounds.size shouldEqual 2
}).unsafeToFuture()
}.unsafeToFuture()
}

"Single fetches for different data sources are executed in multiple rounds if they are in a for comprehension" in {
Expand All @@ -68,9 +68,9 @@ class FetchReportingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
log.rounds.size shouldEqual 2
}).unsafeToFuture()
}.unsafeToFuture()
}

"Single fetches combined with cartesian are run in one round" in {
Expand All @@ -79,9 +79,9 @@ class FetchReportingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
log.rounds.size shouldEqual 1
}).unsafeToFuture()
}.unsafeToFuture()
}

"Single fetches combined with traverse are run in one round" in {
Expand All @@ -93,9 +93,9 @@ class FetchReportingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
log.rounds.size shouldEqual 2
}).unsafeToFuture()
}.unsafeToFuture()
}

"The product of two fetches from the same data source implies batching" in {
Expand All @@ -104,9 +104,9 @@ class FetchReportingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
log.rounds.size shouldEqual 1
}).unsafeToFuture()
}.unsafeToFuture()
}

"The product of concurrent fetches of the same type implies everything fetched in batches" in {
Expand All @@ -129,10 +129,10 @@ class FetchReportingTests extends FetchSpec {

val io = Fetch.runLog[IO](fetch)

io.map({ case (log, result) =>
io.map { case (log, result) =>
log.rounds.size shouldEqual 2
totalBatches(log.rounds) shouldEqual 1
totalFetched(log.rounds) shouldEqual 3 + 1
}).unsafeToFuture()
}.unsafeToFuture()
}
}
Loading