mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 20:55:44 +00:00
Avoid PostgreSQL for empty history projections (#8728)
This commit is contained in:
@@ -294,10 +294,14 @@ class PostgresHistory private[service] (
|
||||
override def sinceFromState(
|
||||
startCount: Int,
|
||||
startingState: GameState
|
||||
): Vector[ActionResultWithResultingState] = withDbLock {
|
||||
): Vector[ActionResultWithResultingState] = withLock {
|
||||
val clamped = math.max(0, math.min(startCount, cachedCount))
|
||||
if clamped != startCount then since(clamped)
|
||||
else replayFromKnownState(emitFromSeq = clamped, startingState = startingState, endExclusiveSeq = cachedCount)
|
||||
if clamped == cachedCount then Vector.empty
|
||||
else
|
||||
withConnection {
|
||||
if clamped != startCount then replayFrom(emitFromSeq = clamped, endExclusiveSeq = cachedCount)
|
||||
else replayFromKnownState(emitFromSeq = clamped, startingState = startingState, endExclusiveSeq = cachedCount)
|
||||
}
|
||||
}
|
||||
|
||||
override def sinceDate(date: Date): Vector[ActionResultWithResultingState] = withDbLock {
|
||||
|
||||
@@ -305,7 +305,7 @@ class PostgresHistorySchemaBatchTest extends AnyFlatSpec with Matchers with Mock
|
||||
history.shardokPlayerAvailableCommands("battle", 1) shouldBe Some(availableCommand)
|
||||
}
|
||||
|
||||
"PostgresHistory state cache" should "serve an exact hit without opening a database connection" in {
|
||||
"PostgresHistory state cache" should "serve exact state and empty range hits without opening a database connection" in {
|
||||
val cachedState = GameState(
|
||||
gameId = 0x1234L,
|
||||
currentRoundId = 7,
|
||||
@@ -338,6 +338,7 @@ class PostgresHistorySchemaBatchTest extends AnyFlatSpec with Matchers with Mock
|
||||
)
|
||||
|
||||
history.stateAfter(1) shouldBe cachedState
|
||||
history.sinceFromState(1, cachedState) shouldBe empty
|
||||
}
|
||||
|
||||
"PostgresHistory Shardok write-behind" should "publish accepted updates before a blocked database write completes" in {
|
||||
|
||||
Reference in New Issue
Block a user