Skip to content

Commit

Permalink
Improve stub-searching performance
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Sep 22, 2023
1 parent 43015ab commit 5ad1c30
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ final class StubResolver(stubDAO: HttpStubDAO[Task], stateDAO: PersistentStateDA
)
)
condition0 = prop[HttpStub](_.method) === method &&
(prop[HttpStub](_.path) ==@ path || pathPatternExpr) &&
(prop[HttpStub](_.path) ==@ path || (prop[HttpStub](_.path).notExists && pathPatternExpr)) &&
prop[HttpStub](_.scope) === scope
condition = (scope == Scope.Countdown).fold(condition0 && prop[HttpStub](_.times) > Option(0), condition0)
candidates0 <- stubDAO.findChunk(condition, 0, Int.MaxValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import cats.tagless.autoFunctorK
import com.github.dwickern.macros.NameOf.*
import org.mongodb.scala.MongoCollection
import org.mongodb.scala.bson.BsonDocument
import org.mongodb.scala.model.Filters.exists
import org.mongodb.scala.model.IndexOptions
import org.mongodb.scala.model.Indexes.*
import simulacrum.typeclass

Expand Down Expand Up @@ -66,11 +64,12 @@ class HttpStubDAOImpl(collection: MongoCollection[BsonDocument])
with HttpStubDAO[Task] {
def createIndexes: Task[Unit] =
createIndex(
ascending(nameOf[HttpStub](_.method), nameOf[HttpStub](_.path), nameOf[HttpStub](_.scope)),
IndexOptions().partialFilterExpression(exists(nameOf[HttpStub](_.path)))
) *> createIndex(
ascending(nameOf[HttpStub](_.method), nameOf[HttpStub](_.pathPattern), nameOf[HttpStub](_.scope)),
IndexOptions().partialFilterExpression(exists(nameOf[HttpStub](_.pathPattern)))
ascending(
nameOf[HttpStub](_.method),
nameOf[HttpStub](_.path),
nameOf[HttpStub](_.scope),
nameOf[HttpStub](_.times)
),
) *> createIndex(
descending(nameOf[HttpStub](_.created))
) *> createIndex(
Expand Down
4 changes: 2 additions & 2 deletions backend/project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ object Settings {

val common = Seq(
organization := "ru.tinkoff",
version := "3.11.1",
scalaVersion := "2.13.11",
version := "3.11.2",
scalaVersion := "2.13.12",
Compile / packageDoc / publishArtifact := false,
Compile / packageSrc / publishArtifact := false,
Compile / doc / sources := Seq.empty,
Expand Down
2 changes: 1 addition & 1 deletion backend/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.9.5
sbt.version = 1.9.6

0 comments on commit 5ad1c30

Please sign in to comment.