Merge "maintenance: recompile if there's no prefetch_file db row" into rvc-dev am: d441ab0307 am: 90d3f64da1 am: 8ee0026dd8 am: 5c3a85cb69

Change-Id: I9be56046f5d73ad2798bf179bd1ea1e643427659
diff --git a/src/maintenance/controller.cc b/src/maintenance/controller.cc
index eb3fb6f..cea7a55 100644
--- a/src/maintenance/controller.cc
+++ b/src/maintenance/controller.cc
@@ -269,9 +269,20 @@
 
   std::string file_path = output_file.FilePath();
 
-  if (!params.recompile && std::filesystem::exists(file_path)) {
-    LOG(DEBUG) << "compiled trace exists in " << file_path;
-    return true;
+  if (!params.recompile) {
+    if (std::filesystem::exists(file_path)) {
+      LOG(DEBUG) << "compiled trace exists in " << file_path;
+
+      db::VersionedComponentName vcn{package_name, activity_name, version};
+      std::optional<db::PrefetchFileModel> prefetch_file =
+          db::PrefetchFileModel::SelectByVersionedComponentName(db, vcn);
+      if (prefetch_file) {
+        return true;
+      } else {
+        LOG(WARNING) << "Missing corresponding prefetch_file db row for " << vcn;
+        // let it go and compile again. we'll insert the prefetch_file at the bottom.
+      }
+    }
   }
 
   std::optional<db::ActivityModel> activity =