~jan0sch/smederee

Showing details for patch d9d372a2aaec96e6e1c591b43b9d962c4e4065a7.
2025-04-26 (Sat), 1:47 PM - Jens Grassel - d9d372a2aaec96e6e1c591b43b9d962c4e4065a7

vcs: Cache repository health run in database and use it.

- load cached health result from db
- use cached on if no repair run is requested
- run check always if repair run is requested
- save result of check command if not already cached
- always show button to run repair command
Summary of changes
2 files modified with 26 lines added and 10 lines removed
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala with 26 added and 8 removed lines
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html with 0 added and 2 removed lines
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-05-10 03:39:53.422983676 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-05-10 03:39:53.422983676 +0000
@@ -708,14 +708,32 @@
                 } else {
                     Chain("--dry-run")
                 }
-            check <- darcs.repair(directory.toNIO)(repositoryName.toString)(options)
-            health = VcsRepositoryHealth(
-                command = "darcs repair --dry-run",
-                exitCode = check.exitValue,
-                stderr = check.stderr,
-                stdout = check.stdout,
-                createdAt = OffsetDateTime.now(ZoneId.of(ZoneOffset.UTC.getId))
-            )
+            // We use a cached run only if the options are not empty i.e. contain `--dry-run`.
+            cachedHealth <- repoAndId.map(_._2).filter(_ => options.nonEmpty) match {
+                case Some(repoId) => vcsMetadataRepo.findHealthCheck(repoId)
+                case _            => Sync[F].pure(None)
+            }
+            // TODO: Re-run the health check if the last patch date is newer than the check run date.
+            health <- cachedHealth match {
+                case Some(healthCheck) => Sync[F].pure(healthCheck)
+                case None =>
+                    darcs
+                        .repair(directory.toNIO)(repositoryName.toString)(options)
+                        .map(check =>
+                            VcsRepositoryHealth(
+                                command = "darcs repair --dry-run",
+                                exitCode = check.exitValue,
+                                stderr = check.stderr,
+                                stdout = check.stdout,
+                                createdAt = OffsetDateTime.now(ZoneId.of(ZoneOffset.UTC.getId))
+                            )
+                        )
+            }
+            // Save the health run if it differs from the one loaded from the database.
+            _ <- (repoAndId.map(_._2), cachedHealth.find(_ === health)) match {
+                case (Some(repoId), None) => vcsMetadataRepo.saveHealthCheck(repoId)(health)
+                case _                    => Sync[F].pure(0)
+            }
             actionBaseUri <- Sync[F].delay(
                 linkConfig.createFullUri(
                     Uri(path =
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html	2025-05-10 03:39:53.422983676 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html	2025-05-10 03:39:53.422983676 +0000
@@ -70,7 +70,6 @@
         </div>
       </div>
     </div>
-    @if(health.exitCode =!= 0) {
     <div class="pure-g">
       <div class="pure-u-1-1 pure-u-md-1-1">
         <div class="l-box">
@@ -78,7 +77,6 @@
         </div>
       </div>
     </div>
-    } else {}
   </div>
 }
 }