mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
Remove SqlSequence, cleanup code (#10042)
changelog_begin changelog_end
This commit is contained in:
parent
8ea240f72a
commit
591176ccb9
@ -68,25 +68,19 @@ private[events] object EventsRange {
|
||||
) => Connection => Vector[A], // takes range, limit, fetchSize hint
|
||||
range: EventsRange[Long],
|
||||
pageSize: Int,
|
||||
): SqlSequence[Vector[A]] = {
|
||||
): Connection => Vector[A] = connection => {
|
||||
val minPageSize = 10 min pageSize max (pageSize / 10)
|
||||
val guessedPageEnd = range.endInclusive min (range.startExclusive + pageSize)
|
||||
SqlSequence
|
||||
.plainQuery(read(range copy (endInclusive = guessedPageEnd), None, Some(pageSize)))
|
||||
.flatMap { arithPage =>
|
||||
val found = arithPage.size
|
||||
if (guessedPageEnd == range.endInclusive || found >= minPageSize)
|
||||
SqlSequence point arithPage
|
||||
else
|
||||
SqlSequence
|
||||
.plainQuery(
|
||||
read(
|
||||
range copy (startExclusive = guessedPageEnd),
|
||||
Some(minPageSize - found),
|
||||
Some(minPageSize - found),
|
||||
)
|
||||
)
|
||||
.map(arithPage ++ _)
|
||||
}
|
||||
val arithPage =
|
||||
read(range copy (endInclusive = guessedPageEnd), None, Some(pageSize))(connection)
|
||||
val found = arithPage.size
|
||||
if (guessedPageEnd == range.endInclusive || found >= minPageSize)
|
||||
arithPage
|
||||
else
|
||||
arithPage ++ read(
|
||||
range copy (startExclusive = guessedPageEnd),
|
||||
Some(minPageSize - found),
|
||||
Some(minPageSize - found),
|
||||
)(connection)
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ private[events] sealed abstract class EventsTableFlatEventsRangeQueries[Offset]
|
||||
offset: Offset,
|
||||
filter: FilterRelation,
|
||||
pageSize: Int,
|
||||
): SqlSequence[Vector[EventsTable.Entry[Raw.FlatEvent]]] = {
|
||||
): Connection => Vector[EventsTable.Entry[Raw.FlatEvent]] = {
|
||||
require(filter.nonEmpty, "The request must be issued by at least one party")
|
||||
|
||||
// Route the request to the correct underlying query
|
||||
@ -111,7 +111,7 @@ private[events] sealed abstract class EventsTableFlatEventsRangeQueries[Offset]
|
||||
pageSize,
|
||||
)
|
||||
case QueryParts.ByLimit(sql) =>
|
||||
SqlSequence.plainQuery(sql(pageSize))
|
||||
sql(pageSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package com.daml.platform.store.appendonlydao.events
|
||||
|
||||
import scalaz.{-\/, Free, Functor, \/-}
|
||||
|
||||
import java.sql.Connection
|
||||
|
||||
object SqlSequence {
|
||||
|
||||
/** A sequence of `SimpleSql`s, terminating in A. */
|
||||
type T[A] = Free[Element, A]
|
||||
|
||||
// this representation is just trampolined Reader, but exposing that
|
||||
// would be unsound because it is _not_ distributive, and anyway
|
||||
// we may want to make the representation more explicit for more complex
|
||||
// analysis (e.g. applying polymorphic transforms to all contained SimpleSqls...)
|
||||
final class Element[+A] private[SqlSequence] (private[SqlSequence] val run: Connection => A)
|
||||
|
||||
object Element {
|
||||
implicit final class syntax[A](private val self: T[A]) extends AnyVal {
|
||||
def executeSql(implicit conn: Connection): A = {
|
||||
@annotation.tailrec
|
||||
def go(self: T[A]): A =
|
||||
self.resume match {
|
||||
case -\/(elt) => go(elt.run(conn))
|
||||
case \/-(a) => a
|
||||
}
|
||||
go(self)
|
||||
}
|
||||
}
|
||||
|
||||
implicit val covariant: Functor[Element] = new Functor[Element] {
|
||||
override def map[A, B](fa: Element[A])(f: A => B) = new Element(run = fa.run andThen f)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO append-only: This probably defeats the purpose, only needed to limit the impact of the SQL query abstraction change. Consider to remove SqlSequence.
|
||||
def plainQuery[A](query: Connection => A): T[A] =
|
||||
Free liftF new Element(query)
|
||||
|
||||
def point[A](a: A): T[A] = Free point a
|
||||
}
|
@ -107,7 +107,7 @@ private[appendonlydao] final class TransactionsReader(
|
||||
EventsRange(range.startExclusive._2, range.endInclusive._2),
|
||||
filter,
|
||||
pageSize,
|
||||
).executeSql,
|
||||
)(connection),
|
||||
range.startExclusive._1,
|
||||
pruned =>
|
||||
s"Transactions request from ${range.startExclusive._1.toHexString} to ${range.endInclusive._1.toHexString} precedes pruned offset ${pruned.toHexString}",
|
||||
@ -210,7 +210,7 @@ private[appendonlydao] final class TransactionsReader(
|
||||
range = EventsRange(range.startExclusive._2, range.endInclusive._2),
|
||||
pageSize = pageSize,
|
||||
),
|
||||
).executeSql,
|
||||
)(connection),
|
||||
range.startExclusive._1,
|
||||
pruned =>
|
||||
s"Transactions request from ${range.startExclusive._1.toHexString} to ${range.endInclusive._1.toHexString} precedes pruned offset ${pruned.toHexString}",
|
||||
@ -359,7 +359,7 @@ private[appendonlydao] final class TransactionsReader(
|
||||
range,
|
||||
filter,
|
||||
pageSize,
|
||||
).executeSql,
|
||||
)(connection),
|
||||
activeAt,
|
||||
pruned =>
|
||||
s"Active contracts request after ${activeAt.toHexString} precedes pruned offset ${pruned.toHexString}",
|
||||
|
@ -11,8 +11,6 @@ import com.daml.lf.transaction.Node.KeyWithMaintainers
|
||||
*/
|
||||
package object events {
|
||||
|
||||
type SqlSequence[A] = SqlSequence.T[A]
|
||||
|
||||
import com.daml.lf.value.{Value => lfval}
|
||||
type ContractId = lfval.ContractId
|
||||
val ContractId = com.daml.lf.value.Value.ContractId
|
||||
|
Loading…
Reference in New Issue
Block a user