From df444f46d402e057ae32164260d1e4d73a60dd32 Mon Sep 17 00:00:00 2001 From: Adrien Piquerez Date: Mon, 19 Aug 2024 15:11:31 +0200 Subject: [PATCH] Fix RelevanceTests --- modules/data/src/main/resources/subindex.txt | 2 +- modules/server/src/it/scala/scaladex/RelevanceTest.scala | 4 +++- .../main/scala/scaladex/server/route/ProjectPages.scala | 6 +++--- .../main/scala/scaladex/server/service/AdminService.scala | 6 +++--- .../{ArtifactsService.scala => ArtifactService.scala} | 3 ++- .../scala/scaladex/server/service/PublishProcess.scala | 8 ++++---- 6 files changed, 16 insertions(+), 13 deletions(-) rename modules/server/src/main/scala/scaladex/server/service/{ArtifactsService.scala => ArtifactService.scala} (94%) diff --git a/modules/data/src/main/resources/subindex.txt b/modules/data/src/main/resources/subindex.txt index 6a773d483..77dd784cc 100644 --- a/modules/data/src/main/resources/subindex.txt +++ b/modules/data/src/main/resources/subindex.txt @@ -128,7 +128,7 @@ foundweekends/giter8 cb372/scalacache blemale/scaffeine scala/scala -lampepfl/dotty +scala/scala3 sbt/zinc scala-js/scala-js scala-native/scala-native diff --git a/modules/server/src/it/scala/scaladex/RelevanceTest.scala b/modules/server/src/it/scala/scaladex/RelevanceTest.scala index 248660940..e636d95ac 100644 --- a/modules/server/src/it/scala/scaladex/RelevanceTest.scala +++ b/modules/server/src/it/scala/scaladex/RelevanceTest.scala @@ -20,6 +20,7 @@ import scaladex.server.service.SearchSynchronizer import scaladex.core.model.search.PageParams import scaladex.server.service.DependencyUpdater import scaladex.core.service.ProjectService +import scaladex.server.service.ArtifactService class RelevanceTest extends TestKit(ActorSystem("SbtActorTest")) with AsyncFunSuiteLike with BeforeAndAfterAll { @@ -40,12 +41,13 @@ class RelevanceTest extends TestKit(ActorSystem("SbtActorTest")) with AsyncFunSu val projectService = new ProjectService(database) val searchSync = new SearchSynchronizer(database, projectService, searchEngine) val projectDependenciesUpdater = new DependencyUpdater(database, projectService) + val artifactService = new ArtifactService(database) IO.fromFuture(IO { for { _ <- Init.run(database, filesystem) _ <- searchEngine.init(true) - _ <- projectDependenciesUpdater.updateAll() + _ <- artifactService.updateAllLatestVersions().zip(projectDependenciesUpdater.updateAll()) _ <- searchSync.syncAll() _ <- searchEngine.refresh() } yield () 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 fd2402c79..c3d3f8aaf 100644 --- a/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala +++ b/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala @@ -21,7 +21,7 @@ import scaladex.core.service.SearchEngine import scaladex.core.web.ArtifactPageParams import scaladex.core.web.ArtifactsPageParams import scaladex.server.TwirlSupport._ -import scaladex.server.service.ArtifactsService +import scaladex.server.service.ArtifactService import scaladex.server.service.SearchSynchronizer import scaladex.view.html.forbidden import scaladex.view.html.notfound @@ -31,7 +31,7 @@ class ProjectPages(env: Env, database: SchedulerDatabase, searchEngine: SearchEn implicit executionContext: ExecutionContext ) extends LazyLogging { private val projectService = new ProjectService(database) - private val artifactsService = new ArtifactsService(database) + private val artifactService = new ArtifactService(database) private val searchSynchronizer = new SearchSynchronizer(database, projectService, searchEngine) def route(user: Option[UserState]): Route = @@ -158,7 +158,7 @@ class ProjectPages(env: Env, database: SchedulerDatabase, searchEngine: SearchEn editForm { form => val updateF = for { _ <- database.updateProjectSettings(projectRef, form) - _ <- artifactsService.updateLatestVersions(projectRef, form.preferStableVersion) + _ <- artifactService.updateLatestVersions(projectRef, form.preferStableVersion) _ <- searchSynchronizer.syncProject(projectRef) } yield () onComplete(updateF) { 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 af361f848..21b30efce 100644 --- a/modules/server/src/main/scala/scaladex/server/service/AdminService.scala +++ b/modules/server/src/main/scala/scaladex/server/service/AdminService.scala @@ -32,7 +32,7 @@ class AdminService( val searchSynchronizer = new SearchSynchronizer(database, projectService, searchEngine) val projectDependenciesUpdater = new DependencyUpdater(database, projectService) val userSessionService = new UserSessionService(database) - val artifactsService = new ArtifactsService(database) + val artifactService = new ArtifactService(database) val githubUpdaterOpt: Option[GithubUpdater] = githubClientOpt.map(client => new GithubUpdater(database, client)) private val jobs: Map[String, JobScheduler] = { @@ -40,9 +40,9 @@ class AdminService( new JobScheduler(Job.syncSearch, searchSynchronizer.syncAll), new JobScheduler(Job.projectDependencies, projectDependenciesUpdater.updateAll), new JobScheduler(Job.projectCreationDates, updateProjectCreationDate), - new JobScheduler(Job.moveArtifacts, artifactsService.moveAll), + new JobScheduler(Job.moveArtifacts, artifactService.moveAll), new JobScheduler(Job.userSessions, userSessionService.updateAll), - new JobScheduler(Job.latestArtifacts, artifactsService.updateAllLatestVersions) + new JobScheduler(Job.latestArtifacts, artifactService.updateAllLatestVersions) ) ++ githubClientOpt.map { client => val githubUpdater = new GithubUpdater(database, client) diff --git a/modules/server/src/main/scala/scaladex/server/service/ArtifactsService.scala b/modules/server/src/main/scala/scaladex/server/service/ArtifactService.scala similarity index 94% rename from modules/server/src/main/scala/scaladex/server/service/ArtifactsService.scala rename to modules/server/src/main/scala/scaladex/server/service/ArtifactService.scala index 0f9a5a090..bcea99294 100644 --- a/modules/server/src/main/scala/scaladex/server/service/ArtifactsService.scala +++ b/modules/server/src/main/scala/scaladex/server/service/ArtifactService.scala @@ -11,7 +11,7 @@ import scaladex.core.model._ import scaladex.core.service.SchedulerDatabase import scaladex.core.util.ScalaExtensions._ -class ArtifactsService(database: SchedulerDatabase)(implicit ec: ExecutionContext) extends LazyLogging { +class ArtifactService(database: SchedulerDatabase)(implicit ec: ExecutionContext) extends LazyLogging { def insertArtifact(artifact: Artifact, dependencies: Seq[ArtifactDependency]): Future[Boolean] = { val unknownStatus = GithubStatus.Unknown(Instant.now) for { @@ -40,6 +40,7 @@ class ArtifactsService(database: SchedulerDatabase)(implicit ec: ExecutionContex for { projectStatuses <- database.getAllProjectsStatuses() refs = projectStatuses.collect { case (ref, status) if status.isOk || status.isUnknown || status.isFailed => ref } + _ = logger.info(s"Updating latest versions of ${refs.size} projects") total <- refs.mapSync(updateLatestVersions).map(_.sum) } yield s"Updated $total artifacts in ${refs.size} projects" diff --git a/modules/server/src/main/scala/scaladex/server/service/PublishProcess.scala b/modules/server/src/main/scala/scaladex/server/service/PublishProcess.scala index 5854545d8..152f00960 100644 --- a/modules/server/src/main/scala/scaladex/server/service/PublishProcess.scala +++ b/modules/server/src/main/scala/scaladex/server/service/PublishProcess.scala @@ -35,7 +35,7 @@ class PublishProcess( githubExtractor: GithubRepoExtractor, converter: ArtifactConverter, database: WebDatabase, - artifactsService: ArtifactsService, + artifactService: ArtifactService, pomsReader: PomsReader, env: Env )(implicit system: ActorSystem) @@ -78,7 +78,7 @@ class PublishProcess( converter.convert(pom, repo, creationDate) match { case Some((artifact, deps)) => for { - isNewProject <- artifactsService.insertArtifact(artifact, deps) + isNewProject <- artifactService.insertArtifact(artifact, deps) _ <- if (isNewProject && userState.nonEmpty) { val githubUpdater = new GithubUpdater(database, new GithubClientImpl(userState.get.info.token)) @@ -108,7 +108,7 @@ object PublishProcess { val githubExtractor = new GithubRepoExtractor(paths) val converter = new ArtifactConverter(paths) val pomsReader = new PomsReader(new CoursierResolver) - val artifactsService = new ArtifactsService(database) - new PublishProcess(filesystem, githubExtractor, converter, database, artifactsService, pomsReader, env) + val artifactService = new ArtifactService(database) + new PublishProcess(filesystem, githubExtractor, converter, database, artifactService, pomsReader, env) } }