From 162f60470c609f992221414e7394e7c24dba7e7a Mon Sep 17 00:00:00 2001 From: rschrieken Date: Sat, 12 Sep 2020 17:30:56 +0200 Subject: [PATCH] add an updatestatus on the index page, queries sys.database so might need extra scrutiny for performance before merged --- .../Controllers/HomeController.cs | 8 ++++++++ App/StackExchange.DataExplorer/Views/Home/Index.cshtml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/App/StackExchange.DataExplorer/Controllers/HomeController.cs b/App/StackExchange.DataExplorer/Controllers/HomeController.cs index 0d43753a..8790da8e 100644 --- a/App/StackExchange.DataExplorer/Controllers/HomeController.cs +++ b/App/StackExchange.DataExplorer/Controllers/HomeController.cs @@ -19,6 +19,14 @@ public ActionResult Index() ViewData["LastUpdate"] = Current.DB.Query("SELECT MAX(LastPost) FROM Sites").FirstOrDefault(); + // sp_Refresh_Database https://gist.github.com/NickCraver/f009ab6e0d6b85ae54f6 + // will create a [name]_Temp database when the restore starts + // we rely on that implementation detail to determine if + // a restore of data is in progress + ViewData["UpdateStatus"] = Current.DB.Query(@"SELECT TOP 1 CASE WHEN [name] LIKE '%_Temp' THEN 'restoring' ELSE NULL END [status] +FROM [sys].[databases] +ORDER BY [create_date] DESC").FirstOrDefault(); + return View(sites); } diff --git a/App/StackExchange.DataExplorer/Views/Home/Index.cshtml b/App/StackExchange.DataExplorer/Views/Home/Index.cshtml index f239947d..adcb72e5 100644 --- a/App/StackExchange.DataExplorer/Views/Home/Index.cshtml +++ b/App/StackExchange.DataExplorer/Views/Home/Index.cshtml @@ -3,7 +3,7 @@ @{this.SetPageTitle("Stack Exchange Data Explorer");}
- Data updated @((ViewData["LastUpdate"] as DateTime?).ToRelativeTime()) + Data updated @((ViewData["LastUpdate"] as DateTime?).ToRelativeTime()) @(ViewData["UpdateStatus"])
    @foreach (Site site in Model)