diff --git a/modules/template/src/main/scala/scaladex/view/model/ProjectHeader.scala b/modules/core/shared/src/main/scala/scaladex/core/model/ProjectHeader.scala similarity index 57% rename from modules/template/src/main/scala/scaladex/view/model/ProjectHeader.scala rename to modules/core/shared/src/main/scala/scaladex/core/model/ProjectHeader.scala index 52653ae00..b92cdc404 100644 --- a/modules/template/src/main/scala/scaladex/view/model/ProjectHeader.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/ProjectHeader.scala @@ -1,45 +1,34 @@ -package scaladex.view.model - -import scaladex.core.model.Artifact -import scaladex.core.model.BinaryVersion -import scaladex.core.model.Language -import scaladex.core.model.MillPlugin -import scaladex.core.model.Platform -import scaladex.core.model.Project -import scaladex.core.model.SbtPlugin -import scaladex.core.model.Scala -import scaladex.core.model.ScalaJs -import scaladex.core.model.ScalaNative -import scaladex.core.model.SemanticVersion +package scaladex.core.model object ProjectHeader { def apply( ref: Project.Reference, - latestArtifacts: Seq[Artifact], + artifacts: Seq[Artifact], versionCount: Long, defaultArtifactName: Option[Artifact.Name], preferStableVersion: Boolean ): Option[ProjectHeader] = - Option.when(latestArtifacts.nonEmpty) { - new ProjectHeader(ref, latestArtifacts, versionCount, defaultArtifactName, preferStableVersion) + Option.when(artifacts.nonEmpty) { + new ProjectHeader(ref, artifacts, versionCount, defaultArtifactName, preferStableVersion) } } final case class ProjectHeader( ref: Project.Reference, - latestArtifacts: Seq[Artifact], + artifacts: Seq[Artifact], versionCount: Long, defaultArtifactName: Option[Artifact.Name], preferStableVersion: Boolean ) { - def artifactNames: Seq[Artifact.Name] = latestArtifacts.map(_.artifactName).distinct.sorted - def languages: Seq[Language] = latestArtifacts.map(_.language).distinct.sorted - def platforms: Seq[Platform] = latestArtifacts.map(_.platform).distinct.sorted + lazy val defaultArtifact: Artifact = getDefaultArtifact(None, None) + lazy val latestVersion: SemanticVersion = defaultArtifact.version + lazy val latestArtifacts: Seq[Artifact] = artifacts.filter(_.version == latestVersion) + lazy val latestLanguages: Seq[Language] = latestArtifacts.map(_.language).distinct.sorted + lazy val latestPlatforms: Seq[Platform] = latestArtifacts.map(_.platform).distinct.sorted + def allArtifactNames: Seq[Artifact.Name] = artifacts.map(_.artifactName).distinct.sorted def platforms(artifactName: Artifact.Name): Seq[Platform] = - latestArtifacts.filter(_.artifactName == artifactName).map(_.platform).distinct.sorted(Platform.ordering.reverse) - - def defaultVersion: SemanticVersion = getDefaultArtifact(None, None).version + artifacts.filter(_.artifactName == artifactName).map(_.platform).distinct.sorted(Platform.ordering.reverse) def artifactsUrl: String = artifactsUrl(getDefaultArtifact(None, None), withBinaryVersion = false) @@ -56,9 +45,9 @@ final case class ProjectHeader( } def getDefaultArtifact(language: Option[Language], platform: Option[Platform]): Artifact = { - val artifacts = latestArtifacts + val filteredArtifacts = artifacts .filter(artifact => language.forall(_ == artifact.language) && platform.forall(_ == artifact.platform)) - val stableArtifacts = artifacts.filter(_.version.isStable) + val stableArtifacts = filteredArtifacts.filter(_.version.isStable) def byName(artifacts: Seq[Artifact]): Option[Artifact] = defaultArtifactName.toSeq @@ -66,7 +55,7 @@ final case class ProjectHeader( .maxByOption(_.binaryVersion) def ofVersion(version: SemanticVersion): Artifact = - artifacts + filteredArtifacts .filter(_.version == version) .maxBy(a => (a.binaryVersion, a.artifactName))( Ordering.Tuple2(Ordering[BinaryVersion], Ordering[Artifact.Name].reverse) @@ -78,18 +67,18 @@ final case class ProjectHeader( if (preferStableVersion) { byName(stableArtifacts) - .orElse(byName(artifacts)) + .orElse(byName(filteredArtifacts)) .orElse(byLatestVersion(stableArtifacts)) - .orElse(byLatestVersion(artifacts)) + .orElse(byLatestVersion(filteredArtifacts)) .get } else { - byName(artifacts).orElse(byLatestVersion(artifacts)).get + byName(filteredArtifacts).orElse(byLatestVersion(filteredArtifacts)).get } } - def scalaVersions: Seq[Scala] = languages.collect { case v: Scala => v } - def scalaJsVersions: Seq[ScalaJs] = platforms.collect { case v: ScalaJs => v } - def scalaNativeVersions: Seq[ScalaNative] = platforms.collect { case v: ScalaNative => v } - def sbtVersions: Seq[SbtPlugin] = platforms.collect { case v: SbtPlugin => v } - def millVersions: Seq[MillPlugin] = platforms.collect { case v: MillPlugin => v } + def latestScalaVersions: Seq[Scala] = latestLanguages.collect { case v: Scala => v } + def latestScalaJsVersions: Seq[ScalaJs] = latestPlatforms.collect { case v: ScalaJs => v } + def latestScalaNativeVersions: Seq[ScalaNative] = latestPlatforms.collect { case v: ScalaNative => v } + def latestSbtVersions: Seq[SbtPlugin] = latestPlatforms.collect { case v: SbtPlugin => v } + def latestMillVersions: Seq[MillPlugin] = latestPlatforms.collect { case v: MillPlugin => v } } diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/search/ProjectDocument.scala b/modules/core/shared/src/main/scala/scaladex/core/model/search/ProjectDocument.scala index b4f2508d3..076b2aa88 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/model/search/ProjectDocument.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/search/ProjectDocument.scala @@ -2,16 +2,7 @@ package scaladex.core.model.search import java.time.Instant -import scaladex.core.model.Artifact -import scaladex.core.model.Category -import scaladex.core.model.Language -import scaladex.core.model.MillPlugin -import scaladex.core.model.Platform -import scaladex.core.model.Project -import scaladex.core.model.SbtPlugin -import scaladex.core.model.Scala -import scaladex.core.model.ScalaJs -import scaladex.core.model.ScalaNative +import scaladex.core.model._ // Project document indexed by the search engine final case class ProjectDocument( @@ -24,6 +15,7 @@ final case class ProjectDocument( updateDate: Option[Instant], languages: Seq[Language], platforms: Seq[Platform], + latestVersion: Option[SemanticVersion], dependents: Long, category: Option[Category], formerReferences: Seq[Project.Reference], @@ -50,6 +42,7 @@ object ProjectDocument { None, Seq.empty, Seq.empty, + None, 0, None, Seq.empty, @@ -58,29 +51,25 @@ object ProjectDocument { def apply( project: Project, - artifacts: Seq[Artifact], + header: Option[ProjectHeader], dependents: Long, formerReferences: Seq[Project.Reference] ): ProjectDocument = { val (deprecatedArtifactNames, artifactNames) = - artifacts - .map(_.artifactName) - .distinct - .sorted - .partition(project.settings.deprecatedArtifacts.contains) - import project._ + header.toSeq.flatMap(_.allArtifactNames).partition(project.settings.deprecatedArtifacts.contains) ProjectDocument( - organization, - repository, + project.organization, + project.repository, artifactNames, deprecatedArtifactNames, - hasCli, - creationDate, + project.hasCli, + project.creationDate, updateDate = None, - artifacts.map(_.binaryVersion.language).distinct.sorted, - artifacts.map(_.binaryVersion.platform).distinct.sorted, + header.toSeq.flatMap(_.latestLanguages), + header.toSeq.flatMap(_.latestPlatforms), + header.map(_.latestVersion), dependents, - settings.category, + project.settings.category, formerReferences, project.githubInfo.map(_.toDocument) ) diff --git a/modules/core/shared/src/main/scala/scaladex/core/service/ProjectService.scala b/modules/core/shared/src/main/scala/scaladex/core/service/ProjectService.scala new file mode 100644 index 000000000..7001e8f3f --- /dev/null +++ b/modules/core/shared/src/main/scala/scaladex/core/service/ProjectService.scala @@ -0,0 +1,22 @@ +package scaladex.core.service + +import scala.concurrent.ExecutionContext +import scala.concurrent.Future + +import scaladex.core.model._ + +class ProjectService(database: WebDatabase)(implicit context: ExecutionContext) { + def getProjectHeader(project: Project): Future[Option[ProjectHeader]] = { + val ref = project.reference + for { + latestArtifacts <- database.getLatestArtifacts(ref, project.settings.preferStableVersion) + versionCount <- database.countVersions(ref) + } yield ProjectHeader( + project.reference, + latestArtifacts, + versionCount, + project.settings.defaultArtifact, + project.settings.preferStableVersion + ) + } +} diff --git a/modules/core/shared/src/main/scala/scaladex/core/service/WebDatabase.scala b/modules/core/shared/src/main/scala/scaladex/core/service/WebDatabase.scala index 361164afa..6e5401a58 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/service/WebDatabase.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/service/WebDatabase.scala @@ -5,17 +5,7 @@ import java.util.UUID import scala.concurrent.Future -import scaladex.core.model.Artifact -import scaladex.core.model.ArtifactDependency -import scaladex.core.model.GithubInfo -import scaladex.core.model.GithubStatus -import scaladex.core.model.Language -import scaladex.core.model.Platform -import scaladex.core.model.Project -import scaladex.core.model.ProjectDependency -import scaladex.core.model.SemanticVersion -import scaladex.core.model.UserInfo -import scaladex.core.model.UserState +import scaladex.core.model._ import scaladex.core.web.ArtifactsPageParams trait WebDatabase { diff --git a/modules/template/src/test/scala/scaladex/view/model/ProjectHeaderTests.scala b/modules/core/shared/src/test/scala/scaladex/core/model/ProjectHeaderTests.scala similarity index 96% rename from modules/template/src/test/scala/scaladex/view/model/ProjectHeaderTests.scala rename to modules/core/shared/src/test/scala/scaladex/core/model/ProjectHeaderTests.scala index cd7ae207e..850bb249a 100644 --- a/modules/template/src/test/scala/scaladex/view/model/ProjectHeaderTests.scala +++ b/modules/core/shared/src/test/scala/scaladex/core/model/ProjectHeaderTests.scala @@ -1,4 +1,4 @@ -package scaladex.view.model +package scaladex.core.model import org.scalatest.funspec.AnyFunSpec import org.scalatest.matchers.should.Matchers diff --git a/modules/core/shared/src/test/scala/scaladex/core/test/Values.scala b/modules/core/shared/src/test/scala/scaladex/core/test/Values.scala index 4b056e151..521e2397d 100644 --- a/modules/core/shared/src/test/scala/scaladex/core/test/Values.scala +++ b/modules/core/shared/src/test/scala/scaladex/core/test/Values.scala @@ -20,6 +20,7 @@ import scaladex.core.model.MajorVersion import scaladex.core.model.PatchVersion import scaladex.core.model.Project import scaladex.core.model.Project.Settings +import scaladex.core.model.ProjectHeader import scaladex.core.model.Scala import scaladex.core.model.ScalaJs import scaladex.core.model.ScalaNative @@ -88,8 +89,20 @@ object Values { val project: Project = Project.default(reference, None, Some(githubInfo), Some(settings), now = now) + val projectHeader: ProjectHeader = ProjectHeader( + reference, + Seq(artifact), + 1, + settings.defaultArtifact, + settings.preferStableVersion + ).get val projectDocument: ProjectDocument = - ProjectDocument(project.copy(creationDate = Some(now.minus(1, ChronoUnit.MINUTES))), Seq(artifact), 0, Seq.empty) + ProjectDocument( + project.copy(creationDate = Some(now.minus(1, ChronoUnit.MINUTES))), + Some(projectHeader), + 0, + Seq.empty + ) } object PlayJsonExtra { @@ -231,9 +244,15 @@ object Values { Scope("compile") ) ) - + val versionCount: Int = allArtifacts.map(_.version).distinct.size + val projectHeader: ProjectHeader = ProjectHeader(reference, allArtifacts, versionCount, None, true).get val projectDocument: ProjectDocument = - ProjectDocument(project.copy(creationDate = Some(now.minus(10, ChronoUnit.MINUTES))), allArtifacts, 1, Seq.empty) + ProjectDocument( + project.copy(creationDate = Some(now.minus(10, ChronoUnit.MINUTES))), + Some(projectHeader), + 1, + Seq.empty + ) } object CatsEffect { diff --git a/modules/infra/src/main/scala/scaladex/infra/elasticsearch/ElasticsearchMapping.scala b/modules/infra/src/main/scala/scaladex/infra/elasticsearch/ElasticsearchMapping.scala index b0a7f1b46..401473b99 100644 --- a/modules/infra/src/main/scala/scaladex/infra/elasticsearch/ElasticsearchMapping.scala +++ b/modules/infra/src/main/scala/scaladex/infra/elasticsearch/ElasticsearchMapping.scala @@ -36,6 +36,7 @@ object ElasticsearchMapping { dateField("creationDate"), keywordField("languages"), keywordField("platforms"), + keywordField("latestVersion"), intField("dependents"), keywordField("category"), textField("githubInfo.description").analyzer("english"), diff --git a/modules/infra/src/main/scala/scaladex/infra/elasticsearch/RawProjectDocument.scala b/modules/infra/src/main/scala/scaladex/infra/elasticsearch/RawProjectDocument.scala index 4c36d6676..5549ea23c 100644 --- a/modules/infra/src/main/scala/scaladex/infra/elasticsearch/RawProjectDocument.scala +++ b/modules/infra/src/main/scala/scaladex/infra/elasticsearch/RawProjectDocument.scala @@ -11,6 +11,7 @@ import scaladex.core.model.Category import scaladex.core.model.Language import scaladex.core.model.Platform import scaladex.core.model.Project +import scaladex.core.model.SemanticVersion import scaladex.core.model.search.GithubInfoDocument import scaladex.core.model.search.ProjectDocument @@ -26,6 +27,7 @@ case class RawProjectDocument( updateDate: Option[Instant], languages: Seq[String], platforms: Seq[String], + latestVersion: Option[String], dependents: Long, category: Option[String], formerReferences: Seq[Project.Reference], @@ -41,6 +43,7 @@ case class RawProjectDocument( updateDate, languages.flatMap(Language.fromLabel).sorted, platforms.flatMap(Platform.fromLabel).sorted, + latestVersion.flatMap(SemanticVersion.parse), dependents, category.flatMap(Category.byLabel.get), formerReferences, @@ -66,6 +69,7 @@ object RawProjectDocument { updateDate, languages.map(_.label), platforms.map(_.label), + latestVersion.map(_.encode), dependents, category.map(_.label), formerReferences, diff --git a/modules/server/src/it/scala/scaladex/RelevanceTest.scala b/modules/server/src/it/scala/scaladex/RelevanceTest.scala index 4c87ab9ee..c7d1fa1b9 100644 --- a/modules/server/src/it/scala/scaladex/RelevanceTest.scala +++ b/modules/server/src/it/scala/scaladex/RelevanceTest.scala @@ -19,6 +19,7 @@ import scaladex.infra.sql.DoobieUtils import scaladex.server.service.SearchSynchronizer import scaladex.core.model.search.PageParams import scaladex.server.service.DependencyUpdater +import scaladex.core.service.ProjectService class RelevanceTest extends TestKit(ActorSystem("SbtActorTest")) with AsyncFunSuiteLike with BeforeAndAfterAll { @@ -36,7 +37,8 @@ class RelevanceTest extends TestKit(ActorSystem("SbtActorTest")) with AsyncFunSu val database = new SqlDatabase(datasource, xa) val filesystem = FilesystemStorage(config.filesystem) - val searchSync = new SearchSynchronizer(database, searchEngine) + val projectService = new ProjectService(database) + val searchSync = new SearchSynchronizer(database, projectService, searchEngine) val projectDependenciesUpdater = new DependencyUpdater(database) IO.fromFuture(IO { @@ -111,9 +113,9 @@ class RelevanceTest extends TestKit(ActorSystem("SbtActorTest")) with AsyncFunSu ) } - test("filter _sjs0.6_2.12") { + test("filter _sjs1_2.13") { top( - SearchParams(languages = Seq("2.12"), platforms = Seq("sjs0.6")), + SearchParams(languages = Seq("2.13"), platforms = Seq("sjs1")), List( "scala-js" -> "scala-js" ) @@ -131,9 +133,9 @@ class RelevanceTest extends TestKit(ActorSystem("SbtActorTest")) with AsyncFunSu ) } - test("filter _native0.3_2.11") { + test("filter _native0.4_2.13") { top( - SearchParams(languages = Seq("2.11"), platforms = Seq("native0.3")), + SearchParams(languages = Seq("2.13"), platforms = Seq("native0.4")), List( ("scalaz", "scalaz"), ("scopt", "scopt"), diff --git a/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala b/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala index 0a02614ab..2ac124001 100644 --- a/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala +++ b/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala @@ -15,6 +15,7 @@ import org.apache.pekko.http.scaladsl.model._ import org.apache.pekko.http.scaladsl.server.Directives._ import org.apache.pekko.http.scaladsl.server._ import scaladex.core.model._ +import scaladex.core.service.ProjectService import scaladex.core.service.SearchEngine import scaladex.core.service.WebDatabase import scaladex.core.web.ArtifactPageParams @@ -23,13 +24,13 @@ import scaladex.server.TwirlSupport._ import scaladex.server.service.SearchSynchronizer import scaladex.view.html.forbidden import scaladex.view.html.notfound -import scaladex.view.model.ProjectHeader import scaladex.view.project.html class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)( implicit executionContext: ExecutionContext ) extends LazyLogging { - private val searchSynchronizer = new SearchSynchronizer(database, searchEngine) + private val service = new ProjectService(database) + private val searchSynchronizer = new SearchSynchronizer(database, service, searchEngine) def route(user: Option[UserState]): Route = concat( @@ -41,7 +42,7 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)( artifactsParams { params => getProjectOrRedirect(ref, user) { project => val artifactsF = database.getArtifacts(ref, artifactName, params) - val headerF = getProjectHeader(project).map(_.get) + val headerF = service.getProjectHeader(project).map(_.get) for (artifacts <- artifactsF; header <- headerF) yield { val binaryVersions = artifacts .map(_.binaryVersion) @@ -80,7 +81,7 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)( path(projectM / "artifacts" / artifactNameM / versionM) { (ref, artifactName, artifactVersion) => artifactParams { params => getProjectOrRedirect(ref, user) { project => - val headerF = getProjectHeader(project) + val headerF = service.getProjectHeader(project) val artifactsF = database.getArtifacts(ref, artifactName, artifactVersion) for { artifacts <- artifactsF @@ -115,7 +116,7 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)( getProjectOrRedirect(ref, user) { project => for { artifacts <- database.getArtifacts(project.reference) - header <- getProjectHeader(project) + header <- service.getProjectHeader(project) } yield { val binaryVersionByPlatforms = artifacts .map(_.binaryVersion) @@ -233,34 +234,20 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)( getProjectOrRedirect(ref, Some(user)) { project => for { artifacts <- database.getArtifacts(ref) - header <- getProjectHeader(project) + header <- service.getProjectHeader(project) } yield { val page = html.editproject(env, user, project, header, artifacts) complete(page) } } - private def getProjectHeader(project: Project): Future[Option[ProjectHeader]] = { - val ref = project.reference - for { - latestArtifacts <- database.getLatestArtifacts(ref, project.settings.preferStableVersion) - versionCount <- database.countVersions(ref) - } yield ProjectHeader( - project.reference, - latestArtifacts, - versionCount, - project.settings.defaultArtifact, - project.settings.preferStableVersion - ) - } - private def getProjectPage(ref: Project.Reference, user: Option[UserState]): Route = getProjectOrRedirect(ref, user) { project => for { - header <- getProjectHeader(project) + header <- service.getProjectHeader(project) directDependencies <- header - .map(h => database.getProjectDependencies(ref, h.defaultVersion)) + .map(h => database.getProjectDependencies(ref, h.latestVersion)) .getOrElse(Future.successful(Seq.empty)) reverseDependencies <- database.getProjectDependents(ref) } yield { @@ -288,7 +275,7 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)( private def getBadges(ref: Project.Reference, user: Option[UserState]): Route = getProjectOrRedirect(ref, user) { project => - for (header <- getProjectHeader(project).map(_.get)) yield { + for (header <- service.getProjectHeader(project).map(_.get)) yield { val artifact = header.getDefaultArtifact(None, None) val page = html.badges(env, user, project, header, artifact) complete(StatusCodes.OK, page) diff --git a/modules/server/src/main/scala/scaladex/server/service/AdminService.scala b/modules/server/src/main/scala/scaladex/server/service/AdminService.scala index 8ca6bb917..32789c475 100644 --- a/modules/server/src/main/scala/scaladex/server/service/AdminService.scala +++ b/modules/server/src/main/scala/scaladex/server/service/AdminService.scala @@ -11,6 +11,7 @@ import scaladex.core.model.Project import scaladex.core.model.Project.Settings import scaladex.core.model.UserState import scaladex.core.service.GithubClient +import scaladex.core.service.ProjectService import scaladex.core.service.SchedulerDatabase import scaladex.core.service.SearchEngine import scaladex.core.util.ScalaExtensions._ @@ -27,7 +28,8 @@ class AdminService( extends LazyLogging { import actorSystem.dispatcher - val searchSynchronizer = new SearchSynchronizer(database, searchEngine) + val projectService = new ProjectService(database) + val searchSynchronizer = new SearchSynchronizer(database, projectService, searchEngine) val projectDependenciesUpdater = new DependencyUpdater(database) val userSessionService = new UserSessionService(database) val artifactsService = new ArtifactsService(database) diff --git a/modules/server/src/main/scala/scaladex/server/service/DependencyUpdater.scala b/modules/server/src/main/scala/scaladex/server/service/DependencyUpdater.scala index 274ba5329..253d35fdb 100644 --- a/modules/server/src/main/scala/scaladex/server/service/DependencyUpdater.scala +++ b/modules/server/src/main/scala/scaladex/server/service/DependencyUpdater.scala @@ -6,9 +6,9 @@ import scala.util.control.NonFatal import com.typesafe.scalalogging.LazyLogging import scaladex.core.model.Project +import scaladex.core.model.ProjectHeader import scaladex.core.service.SchedulerDatabase import scaladex.core.util.ScalaExtensions._ -import scaladex.view.model.ProjectHeader class DependencyUpdater(database: SchedulerDatabase)(implicit ec: ExecutionContext) extends LazyLogging { @@ -40,7 +40,7 @@ class DependencyUpdater(database: SchedulerDatabase)(implicit ec: ExecutionConte project.settings.preferStableVersion ) dependencies <- header - .map(h => database.computeProjectDependencies(project.reference, h.defaultVersion)) + .map(h => database.computeProjectDependencies(project.reference, h.latestVersion)) .getOrElse(Future.successful(Seq.empty)) _ <- database.deleteProjectDependencies(project.reference) _ <- database.insertProjectDependencies(dependencies) diff --git a/modules/server/src/main/scala/scaladex/server/service/SearchSynchronizer.scala b/modules/server/src/main/scala/scaladex/server/service/SearchSynchronizer.scala index dfb00a71b..b8f9b8f58 100644 --- a/modules/server/src/main/scala/scaladex/server/service/SearchSynchronizer.scala +++ b/modules/server/src/main/scala/scaladex/server/service/SearchSynchronizer.scala @@ -7,12 +7,14 @@ import com.typesafe.scalalogging.LazyLogging import scaladex.core.model.GithubStatus import scaladex.core.model.Project import scaladex.core.model.search.ProjectDocument +import scaladex.core.service.ProjectService import scaladex.core.service.SearchEngine import scaladex.core.service.WebDatabase import scaladex.core.util.ScalaExtensions._ -class SearchSynchronizer(database: WebDatabase, searchEngine: SearchEngine)(implicit ec: ExecutionContext) - extends LazyLogging { +class SearchSynchronizer(database: WebDatabase, service: ProjectService, searchEngine: SearchEngine)( + implicit ec: ExecutionContext +) extends LazyLogging { def syncAll(): Future[String] = for { allProjects <- database.getAllProjects() @@ -55,9 +57,9 @@ class SearchSynchronizer(database: WebDatabase, searchEngine: SearchEngine)(impl private def insertDocument(project: Project, formerReferences: Seq[Project.Reference]): Future[Unit] = for { - artifacts <- database.getArtifacts(project.reference) + header <- service.getProjectHeader(project) dependents <- database.countProjectDependents(project.reference) - document = ProjectDocument(project, artifacts, dependents, formerReferences) + document = ProjectDocument(project, header, dependents, formerReferences) _ <- searchEngine.insert(document) _ <- formerReferences.mapSync(searchEngine.delete) } yield () diff --git a/modules/template/src/main/twirl/scaladex/view/awesome/resultList.scala.html b/modules/template/src/main/twirl/scaladex/view/awesome/resultList.scala.html index b6a35aeef..1547e3ba3 100644 --- a/modules/template/src/main/twirl/scaladex/view/awesome/resultList.scala.html +++ b/modules/template/src/main/twirl/scaladex/view/awesome/resultList.scala.html @@ -10,7 +10,12 @@
@githubUserAvatar(project.githubInfo.flatMap(_.logo)) -

@project.reference

+

+ @project.reference + @for(latestVersion <- project.latestVersion){ +   @latestVersion.encode + } +

@for(github <- project.githubInfo) { @for(description <- github.description) { diff --git a/modules/template/src/main/twirl/scaladex/view/project/artifact.scala.html b/modules/template/src/main/twirl/scaladex/view/project/artifact.scala.html index 2b7ae19d3..57490cdb5 100644 --- a/modules/template/src/main/twirl/scaladex/view/project/artifact.scala.html +++ b/modules/template/src/main/twirl/scaladex/view/project/artifact.scala.html @@ -4,7 +4,6 @@ @import scaladex.view.Formats @import scaladex.view.html._ @import scaladex.view.InstallTab -@import scaladex.view.model.ProjectHeader @( env: Env, diff --git a/modules/template/src/main/twirl/scaladex/view/project/artifacts.scala.html b/modules/template/src/main/twirl/scaladex/view/project/artifacts.scala.html index 18939a553..09146b2c8 100644 --- a/modules/template/src/main/twirl/scaladex/view/project/artifacts.scala.html +++ b/modules/template/src/main/twirl/scaladex/view/project/artifacts.scala.html @@ -1,4 +1,4 @@ -@import scaladex.core.model.{Artifact, BinaryVersion, Project, SemanticVersion, UserState, Env} +@import scaladex.core.model._ @import scaladex.view.html.main @import scaladex.view.html._ @import scaladex.core.web.ArtifactsPageParams @@ -8,7 +8,6 @@ @import scaladex.core.util.ScalaExtensions._ @import scaladex.core.util.TimeUtils @import scaladex.view.Formats -@import scaladex.view.model.ProjectHeader @import java.time.Instant @( @@ -90,7 +89,7 @@
@platform:
@filters() = {