Bgerstle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/206970

Change subject: prevent storing article titles that fail to load in history
......................................................................

prevent storing article titles that fail to load in history

We optimistically store titles in the history list when they're
requested, but fail to remove them if that title fails to load.

Unit tests to follow in another patch (or amendment to this one, you
decide). Bit of a hacky solution, as this might be vulnerable to race
conditions causing the wrong title to be removed from the history list.

Bug: T95585
Change-Id: Icb8ca87023d983ffcafcef9e76600ab5ce37f4df
---
M MediaWikiKit/MediaWikiKit/MWKHistoryList.h
M MediaWikiKit/MediaWikiKit/MWKHistoryList.m
M Wikipedia/View Controllers/WebView/WebViewController.m
3 files changed, 15 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia 
refs/changes/70/206970/1

diff --git a/MediaWikiKit/MediaWikiKit/MWKHistoryList.h 
b/MediaWikiKit/MediaWikiKit/MWKHistoryList.h
index 08b07ac..66a686e 100644
--- a/MediaWikiKit/MediaWikiKit/MWKHistoryList.h
+++ b/MediaWikiKit/MediaWikiKit/MWKHistoryList.h
@@ -16,6 +16,7 @@
 @property (readonly) NSUInteger length;
 @property (readwrite) BOOL dirty;
 
+- (MWKHistoryEntry*)mostRecentEntry;
 - (MWKHistoryEntry*)entryAtIndex:(NSUInteger)index;
 - (MWKHistoryEntry*)entryForTitle:(MWKTitle*)title;
 
diff --git a/MediaWikiKit/MediaWikiKit/MWKHistoryList.m 
b/MediaWikiKit/MediaWikiKit/MWKHistoryList.m
index efad6f4..7ac6d68 100644
--- a/MediaWikiKit/MediaWikiKit/MWKHistoryList.m
+++ b/MediaWikiKit/MediaWikiKit/MWKHistoryList.m
@@ -17,6 +17,10 @@
     return [entries count];
 }
 
+- (MWKHistoryEntry*)mostRecentEntry {
+    return [entries firstObject];
+}
+
 - (MWKHistoryEntry*)entryAtIndex:(NSUInteger)index {
     return entries[index];
 }
diff --git a/Wikipedia/View Controllers/WebView/WebViewController.m 
b/Wikipedia/View Controllers/WebView/WebViewController.m
index 538e05e..5e8a542 100644
--- a/Wikipedia/View Controllers/WebView/WebViewController.m
+++ b/Wikipedia/View Controllers/WebView/WebViewController.m
@@ -1390,6 +1390,11 @@
 
             case FETCH_FINAL_STATUS_FAILED:
             {
+                MWKHistoryEntry* lastEntry = 
session.userDataStore.historyList.mostRecentEntry;
+                if ([lastEntry.title.prefixedText 
isEqualToString:article.title.prefixedText]) {
+                    [session.userDataStore.historyList removeEntry:lastEntry];
+                    [session.userDataStore save];
+                }
                 NSString* errorMsg = error.localizedDescription;
                 [self showAlert:errorMsg type:ALERT_TYPE_TOP duration:-1];
 
@@ -1400,6 +1405,11 @@
 
             case FETCH_FINAL_STATUS_CANCELLED:
             {
+                MWKHistoryEntry* lastEntry = 
session.userDataStore.historyList.mostRecentEntry;
+                if ([lastEntry.title.prefixedText 
isEqualToString:article.title.prefixedText]) {
+                    [session.userDataStore.historyList removeEntry:lastEntry];
+                    [session.userDataStore save];
+                }
                 // Reminder: do not clear article data here or cancellation 
would blast last good saved article data!
             }
             break;

-- 
To view, visit https://gerrit.wikimedia.org/r/206970
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb8ca87023d983ffcafcef9e76600ab5ce37f4df
Gerrit-PatchSet: 1
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Bgerstle <bgers...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to