From 06a3f8c142568561be815bca19a9590413f50636 Mon Sep 17 00:00:00 2001 From: jim Date: Fri, 2 Oct 2026 09:26:21 -0500 Subject: [PATCH] fix(traverse): import the last no-download record in each file TraverseDirectory imported a record without downloaded files only when the next "Post id:" line appeared, so the final record of every export file was never evaluated and a matching post at the end of a file never reached Posts. Move the check into a local function and call it again after the line loop, so the last record is flushed under exactly the same conditions as every other one. HasImage values at both call sites are unchanged. Co-Authored-By: Claude Opus 5.5 --- URLNotesGrabberCORE/Program.cs | 68 +++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/URLNotesGrabberCORE/Program.cs b/URLNotesGrabberCORE/Program.cs index fab727f..a3e35cd 100644 --- a/URLNotesGrabberCORE/Program.cs +++ b/URLNotesGrabberCORE/Program.cs @@ -1592,42 +1592,49 @@ if (shouldInsert) var urls = new List(); var reblog = new ReblogRecord(); + // A record without downloaded files is only complete once the next + // "Post id:" line (or end of file) is reached, so it is imported then. + void ImportRecordWithoutDownloadedFiles(ReblogRecord record, ref int added) + { + if (record.reblogName != "." && record.postID != "." && record.date != "." && record.reblogURL != "." && record.downloadedFiles == ".") + { + if (!record.reblogURL.Contains("deactivated") + && record.reblogURL.Length != 0 + && ContainsAny(record.reblogURL, contains)) + { + DirectoryInfo currentDir = new DirectoryInfo(path); + if (!headerWasWritten) + { + headerWasWritten = true; + } + string curDir = NormalizeBlogFolderName(currentDir.Name); + urls.Add(string.Format("{0}\t{1}", curDir, record.postID)); + + var recordImportStopwatch = System.Diagnostics.Stopwatch.StartNew(); + DataAccess.AddPost(curDir, long.Parse(record.postID), record.reblogURL, record.date, record.postURL, record.slug, record.reblogKey, + record.reblogName, record.summary, record.quote, record.body, record.tags, record.link, record.photoURL, + record.photoCaption, record.downloadedFiles, record.audioCaption, record.question, record.answer, + record.title, false, rootURL: record.rootURL, postType: filePostType); + recordImportStopwatch.Stop(); + + added++; + directoryRecordsImported++; + if (logRecordImports) + Console.WriteLine($"[Record Import] {curDir}/{record.postID} | {recordImportStopwatch.Elapsed.TotalMilliseconds:F2} ms | DirectoryCount={directoryRecordsImported} | TotalCount={added}"); + + // Output hyperlink and post date + //Console.WriteLine($"https://{record.reblogName}.tumblr.com/post/{record.postID} - {record.date}"); + } + } + } + string[] fileLines = File.ReadAllLines(file); for (int lineIndex = 0; lineIndex < fileLines.Length; lineIndex++) { string line = fileLines[lineIndex]; if (line.StartsWith("Post id:", StringComparison.OrdinalIgnoreCase)) { - if (reblog.reblogName != "." && reblog.postID != "." && reblog.date != "." && reblog.reblogURL != "." && reblog.downloadedFiles == ".") - { - if (!reblog.reblogURL.Contains("deactivated") - && reblog.reblogURL.Length != 0 - && ContainsAny(reblog.reblogURL, contains)) - { - DirectoryInfo currentDir = new DirectoryInfo(path); - if (!headerWasWritten) - { - headerWasWritten = true; - } - string curDir = NormalizeBlogFolderName(currentDir.Name); - urls.Add(string.Format("{0}\t{1}", curDir, reblog.postID)); - - var recordImportStopwatch = System.Diagnostics.Stopwatch.StartNew(); - DataAccess.AddPost(curDir, long.Parse(reblog.postID), reblog.reblogURL, reblog.date, reblog.postURL, reblog.slug, reblog.reblogKey, - reblog.reblogName, reblog.summary, reblog.quote, reblog.body, reblog.tags, reblog.link, reblog.photoURL, - reblog.photoCaption, reblog.downloadedFiles, reblog.audioCaption, reblog.question, reblog.answer, - reblog.title, false, rootURL: reblog.rootURL, postType: filePostType); - recordImportStopwatch.Stop(); - - postsAdded++; - directoryRecordsImported++; - if (logRecordImports) - Console.WriteLine($"[Record Import] {curDir}/{reblog.postID} | {recordImportStopwatch.Elapsed.TotalMilliseconds:F2} ms | DirectoryCount={directoryRecordsImported} | TotalCount={postsAdded}"); - - // Output hyperlink and post date - //Console.WriteLine($"https://{reblog.reblogName}.tumblr.com/post/{reblog.postID} - {reblog.date}"); - } - } + ImportRecordWithoutDownloadedFiles(reblog, ref postsAdded); reblog = new ReblogRecord(); reblog.postID = line.Substring(9).Trim(); } @@ -1777,6 +1784,7 @@ if (shouldInsert) } } } + ImportRecordWithoutDownloadedFiles(reblog, ref postsAdded); urls.Sort();