diff --git a/OneMore/Commands/Tagging/HashtagDialog.cs b/OneMore/Commands/Tagging/HashtagDialog.cs
index 5ae6fd1a86..12d28af5b4 100644
--- a/OneMore/Commands/Tagging/HashtagDialog.cs
+++ b/OneMore/Commands/Tagging/HashtagDialog.cs
@@ -311,11 +311,11 @@ private async void ScanNow(object sender, EventArgs e)
var clock = new Stopwatch();
clock.Start();
- var totalPages = await scanner.Scan();
+ var (dirtyPages, totalPages) = await scanner.Scan();
clock.Stop();
var time = clock.ElapsedMilliseconds;
- logger.WriteLine($"scanned {totalPages} pages in {time}ms");
+ logger.WriteLine($"scanned {totalPages} pages, updating {dirtyPages}, in {time}ms");
PopulateTags(sender, e);
}
diff --git a/OneMore/Commands/Tagging/HashtagScanner.cs b/OneMore/Commands/Tagging/HashtagScanner.cs
index ad0f68915a..549ea1f005 100644
--- a/OneMore/Commands/Tagging/HashtagScanner.cs
+++ b/OneMore/Commands/Tagging/HashtagScanner.cs
@@ -108,8 +108,9 @@ public void Dispose()
/// Scan all notebooks for all hashtags
///
///
- public async Task Scan()
+ public async Task<(int, int)> Scan()
{
+ int dirtyPages = 0;
int totalPages = 0;
// get all notebooks
@@ -125,21 +126,25 @@ public async Task Scan()
var notebookID = notebook.Attribute("ID").Value;
var sections = await one.GetNotebook(notebookID);
- totalPages += await Scan(
+ var (dp, tp) = await Scan(
sections, notebookID, $"/{notebook.Attribute("name").Value}");
+
+ dirtyPages += dp;
+ totalPages += tp;
}
}
provider.WriteScanTime();
- return totalPages;
+ return (dirtyPages, totalPages);
}
- private async Task Scan(XElement parent, string notebookID, string path)
+ private async Task<(int, int)> Scan(XElement parent, string notebookID, string path)
{
//logger.Verbose($"scanning parent {path}");
+ int dirtyPages = 0;
int totalPages = 0;
var sectionRefs = parent.Elements(ns + "Section")
@@ -174,7 +179,10 @@ private async Task Scan(XElement parent, string notebookID, string path)
if (page.Attribute("lastModifiedTime").Value.CompareTo(lastTime) > 0)
{
- await ScanPage(pid, notebookID, sectionID, sectionPath);
+ if (await ScanPage(pid, notebookID, sectionID, sectionPath))
+ {
+ dirtyPages++;
+ }
}
}
@@ -193,16 +201,20 @@ private async Task Scan(XElement parent, string notebookID, string path)
{
foreach (var group in groups)
{
- totalPages = await Scan(
+ var (dp, tp) = await Scan(
group, notebookID, $"{path}/{group.Attribute("name").Value}");
+
+ dirtyPages += dp;
+ totalPages += tp;
}
}
- return totalPages;
+ return (dirtyPages, totalPages);
}
- private async Task ScanPage(string pageID, string notebookID, string sectionID, string path)
+ private async Task ScanPage(
+ string pageID, string notebookID, string sectionID, string path)
{
Page page;
@@ -213,7 +225,7 @@ private async Task ScanPage(string pageID, string notebookID, string sectionID,
catch (Exception exc)
{
logger.WriteLine("error scanning page, possibly locked", exc);
- return;
+ return false;
}
var title = page.Title;
@@ -284,15 +296,16 @@ private async Task ScanPage(string pageID, string notebookID, string sectionID,
// TODO: could track moreID+pageID to determine if REPLACE is needed; but then
// need to read that info first as well; see where the design goes...
- // TODO: how to clean up deleted pages?
-
// TODO: should this be wrapped in a tx along with the above statements?
provider.WritePageInfo(
scanner.MoreID, pageID, titleID, notebookID, sectionID, path, title);
logger.WriteLine($"updating tags on page {path}/{title}");
+ return true;
}
+
+ return false;
}
}
}
diff --git a/OneMore/Commands/Tagging/HashtagService.cs b/OneMore/Commands/Tagging/HashtagService.cs
index 41becb8b5d..5211b18d22 100644
--- a/OneMore/Commands/Tagging/HashtagService.cs
+++ b/OneMore/Commands/Tagging/HashtagService.cs
@@ -95,11 +95,16 @@ private async Task Scan()
clock.Start();
using var scanner = new HashtagScanner();
- var totalPages = await scanner.Scan();
+ var (dirtyPages, totalPages) = await scanner.Scan();
clock.Stop();
var time = clock.ElapsedMilliseconds;
- logger.WriteLine($"hashtag service scanned {totalPages} pages in {time}ms");
+
+ if (dirtyPages > 0 || time > 1000)
+ {
+ logger.WriteLine(
+ $"hashtag service scanned {totalPages} pages, updating {dirtyPages}, in {time}ms");
+ }
}
}
}