Skip to content

Commit

Permalink
report updated tagged pages
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Dec 29, 2023
1 parent ac0e307 commit bf3b19a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
4 changes: 2 additions & 2 deletions OneMore/Commands/Tagging/HashtagDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
35 changes: 24 additions & 11 deletions OneMore/Commands/Tagging/HashtagScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ public void Dispose()
/// Scan all notebooks for all hashtags
/// </summary>
/// <returns></returns>
public async Task<int> Scan()
public async Task<(int, int)> Scan()
{
int dirtyPages = 0;
int totalPages = 0;

// get all notebooks
Expand All @@ -125,21 +126,25 @@ public async Task<int> 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<int> 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")
Expand Down Expand Up @@ -174,7 +179,10 @@ private async Task<int> 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++;
}
}
}

Expand All @@ -193,16 +201,20 @@ private async Task<int> 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<bool> ScanPage(
string pageID, string notebookID, string sectionID, string path)
{
Page page;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
9 changes: 7 additions & 2 deletions OneMore/Commands/Tagging/HashtagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}

0 comments on commit bf3b19a

Please sign in to comment.