Skip to content

Commit

Permalink
Remove unused ReleaseTable and ReleaseDependenciesTable
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Aug 13, 2024
1 parent e38c282 commit 904ed03
Show file tree
Hide file tree
Showing 17 changed files with 7 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ case class Artifact(

val mavenReference: Artifact.MavenReference = Artifact.MavenReference(groupId.value, artifactId, version.encode)

def release: Release =
Release(projectRef.organization, projectRef.repository, platform, language, version, releaseDate)

def releaseDateFormat: String = Artifact.dateFormatter.format(releaseDate)

def fullHttpUrl(env: Env): String =
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import scaladex.core.model.Artifact.MavenReference
import scaladex.core.model.ArtifactDependency
import scaladex.core.model.Project
import scaladex.core.model.ProjectDependency
import scaladex.core.model.ReleaseDependency
import scaladex.core.model.SemanticVersion

trait SchedulerDatabase extends WebDatabase {
Expand All @@ -18,11 +17,9 @@ trait SchedulerDatabase extends WebDatabase {
def updateProjectCreationDate(ref: Project.Reference, creationDate: Instant): Future[Unit]
def computeAllProjectsCreationDates(): Future[Seq[(Instant, Project.Reference)]]

// project dependencies (and release dependencies)
// project dependencies
def computeProjectDependencies(reference: Project.Reference, version: SemanticVersion): Future[Seq[ProjectDependency]]
def computeReleaseDependencies(): Future[Seq[ReleaseDependency]]
def insertProjectDependencies(projectDependencies: Seq[ProjectDependency]): Future[Int]
def insertReleaseDependencies(projectDependencies: Seq[ReleaseDependency]): Future[Int]
def deleteProjectDependencies(ref: Project.Reference): Future[Int]

// artifacts and its dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import scaladex.core.model.Language
import scaladex.core.model.Platform
import scaladex.core.model.Project
import scaladex.core.model.ProjectDependency
import scaladex.core.model.ReleaseDependency
import scaladex.core.model.SemanticVersion
import scaladex.core.model.UserInfo
import scaladex.core.model.UserState
Expand Down Expand Up @@ -124,7 +123,6 @@ class InMemoryDatabase extends SchedulerDatabase {
ref: Project.Reference,
version: SemanticVersion
): Future[Seq[ProjectDependency]] = ???
override def computeReleaseDependencies(): Future[Seq[ReleaseDependency]] = ???

override def computeAllProjectsCreationDates(): Future[Seq[(Instant, Project.Reference)]] = ???

Expand All @@ -133,8 +131,6 @@ class InMemoryDatabase extends SchedulerDatabase {

override def insertProjectDependencies(projectDependencies: Seq[ProjectDependency]): Future[Int] = ???

override def insertReleaseDependencies(releaseDependency: Seq[ReleaseDependency]): Future[Int] = ???

override def countProjectDependents(ref: Project.Reference): Future[Long] =
Future.successful(0)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE releases, release_dependencies;

15 changes: 4 additions & 11 deletions modules/infra/src/main/scala/scaladex/infra/SqlDatabase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import scaladex.core.model.Language
import scaladex.core.model.Platform
import scaladex.core.model.Project
import scaladex.core.model.ProjectDependency
import scaladex.core.model.ReleaseDependency
import scaladex.core.model.SemanticVersion
import scaladex.core.model.UserInfo
import scaladex.core.model.UserState
Expand All @@ -30,13 +29,14 @@ import scaladex.infra.sql.GithubInfoTable
import scaladex.infra.sql.ProjectDependenciesTable
import scaladex.infra.sql.ProjectSettingsTable
import scaladex.infra.sql.ProjectTable
import scaladex.infra.sql.ReleaseDependenciesTable
import scaladex.infra.sql.ReleaseTable
import scaladex.infra.sql.UserSessionsTable

class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) extends SchedulerDatabase with LazyLogging {
private val flyway = DoobieUtils.flyway(datasource)
def migrate: IO[Unit] = IO(flyway.migrate())
def migrate: IO[Unit] = IO {
flyway.repair()
flyway.migrate()
}
def dropTables: IO[Unit] = IO(flyway.clean())

override def insertArtifact(
Expand All @@ -48,7 +48,6 @@ class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) exten
for {
isNewProject <- insertProjectRef(artifact.projectRef, unknownStatus)
_ <- run(ArtifactTable.insertIfNotExist(artifact))
_ <- run(ReleaseTable.insertIfNotExists.run(artifact.release))
_ <- insertDependencies(dependencies)
} yield isNewProject
}
Expand Down Expand Up @@ -179,19 +178,13 @@ class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) exten
): Future[Seq[ProjectDependency]] =
run(ArtifactDependencyTable.computeProjectDependencies.to[Seq]((ref, version)))

override def computeReleaseDependencies(): Future[Seq[ReleaseDependency]] =
run(ArtifactDependencyTable.computeReleaseDependency.to[Seq])

override def insertProjectDependencies(projectDependencies: Seq[ProjectDependency]): Future[Int] =
if (projectDependencies.isEmpty) Future.successful(0)
else run(ProjectDependenciesTable.insertOrUpdate.updateMany(projectDependencies))

override def deleteProjectDependencies(ref: Project.Reference): Future[Int] =
run(ProjectDependenciesTable.deleteBySource.run(ref))

override def insertReleaseDependencies(releaseDependency: Seq[ReleaseDependency]): Future[Int] =
run(ReleaseDependenciesTable.insertIfNotExists.updateMany(releaseDependency))

override def countProjectDependents(projectRef: Project.Reference): Future[Long] =
run(ProjectDependenciesTable.countDependents.unique(projectRef))

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import scaladex.core.model.Artifact
import scaladex.core.model.ArtifactDependency
import scaladex.core.model.Project
import scaladex.core.model.ProjectDependency
import scaladex.core.model.ReleaseDependency
import scaladex.core.model.SemanticVersion
import scaladex.infra.sql.DoobieUtils.Mappings._
import scaladex.infra.sql.DoobieUtils._
Expand Down Expand Up @@ -74,16 +73,6 @@ object ArtifactDependencyTable {
Seq("d.organization", "d.repository", "d.version", "t.organization", "t.repository", "t.version", "d.scope")
).contramap { case (ref, version) => (ref, version, ref) }

val computeReleaseDependency: Query0[ReleaseDependency] = {
val sourceReleaseFields = ReleaseTable.primaryKeys.map("d." + _)
val targetReleaseFields = ReleaseTable.primaryKeys.map("t." + _)
selectRequest(
fullJoin,
sourceReleaseFields ++ Seq("MIN(d.release_date)") ++ targetReleaseFields ++ Seq("MIN(t.release_date)", "d.scope"),
groupBy = (sourceReleaseFields ++ targetReleaseFields) ++ Seq("d.scope")
)
}

val selectDependencyFromProject: Query[Project.Reference, ArtifactDependency] =
selectRequest(
tableWithSourceArtifact,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import scaladex.core.model.Artifact
import scaladex.core.model.Language
import scaladex.core.model.Platform
import scaladex.core.model.Project
import scaladex.core.model.Release
import scaladex.core.model.SemanticVersion
import scaladex.infra.sql.DoobieUtils.Mappings._
import scaladex.infra.sql.DoobieUtils._
Expand Down Expand Up @@ -115,13 +114,6 @@ object ArtifactTable {
groupBy = projectReferenceFields
)

val getReleasesFromArtifacts: Query0[Release] =
selectRequest(
table,
Seq("organization", "repository", "platform", "language_version", "version", "MIN(release_date)"),
groupBy = Seq("organization", "repository ", "platform ", "language_version", "version")
)

def selectLatestArtifacts(stableOnly: Boolean): Query[Project.Reference, Artifact] =
selectRequest1(latestDateTable(stableOnly), fields.map(c => s"a.$c"))

Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions modules/infra/src/main/scala/scaladex/infra/sql/ReleaseTable.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ class ArtifactDependencyTableTests extends AnyFunSpec with BaseDatabaseSuite wit
it("check selectDirectDependency")(check(ArtifactDependencyTable.selectDirectDependency))
it("check selectReverseDependency")(check(ArtifactDependencyTable.selectReverseDependency))
it("check computeProjectDependencies")(check(ArtifactDependencyTable.computeProjectDependencies))
it("check computeReleaseDependency")(check(ArtifactDependencyTable.computeReleaseDependency))
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ArtifactTableTests extends AnyFunSpec with BaseDatabaseSuite with Matchers
it("check selectMavenReference")(check(selectMavenReference))
it("check updateReleaseDate")(check(updateReleaseDate))
it("check selectByMavenReference")(check(selectByMavenReference))
it("check getReleasesFromArtifacts")(check(getReleasesFromArtifacts))
it("check countVersionsByProject")(check(countVersionsByProject))
it("check selectArtifactByParams") {
check(selectArtifactByParams(false))
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class DependencyUpdater(database: SchedulerDatabase)(implicit ec: ExecutionConte
def updateAll(): Future[String] =
for {
status <- updateProjectDependencyTable()
_ <- updateReleaseDependencyTable()
} yield status

def updateProjectDependencyTable(): Future[String] =
Expand Down Expand Up @@ -50,29 +49,4 @@ class DependencyUpdater(database: SchedulerDatabase)(implicit ec: ExecutionConte
logger.error(s"Failed to update dependencies of ${project.reference} of status ${project.githubStatus}", cause)
}
}

def updateReleaseDependencyTable(): Future[Unit] =
for {
releaseDependencies <- database
.computeReleaseDependencies()
.mapFailure(e =>
new Exception(
s"Failed to compute release dependencies because of ${e.getMessage}"
)
)
_ = logger.info(s"will try to insert ${releaseDependencies.size} releaseDependencies")
_ <- releaseDependencies
.grouped(10000)
.map(releaseDependencies =>
database
.insertReleaseDependencies(releaseDependencies)
.mapFailure(e =>
new Exception(
s"Failed to insert release dependencies because of ${e.getMessage}"
)
)
)
.sequence

} yield ()
}

0 comments on commit 904ed03

Please sign in to comment.