@@ -29,43 +29,39 @@ internal static class RequestHelper
2929 ?? jresult [ "query-continue" ] ? . AsObject ( ) . FirstOrDefault ( ) . Value ) ;
3030 }
3131
32- public static int ParseContinuationParameters ( JsonNode jresult , IDictionary < string , object ? > queryParams ,
33- IDictionary < string , object ? > ? continuationParams )
32+ public static int ParseContinuationParameters ( JsonNode jresult , IDictionary < string , object > queryParams ,
33+ IDictionary < string , string > ? continuationParams )
3434 {
3535 var continuation = FindQueryContinuationParameterRoot ( jresult ) ;
3636 // No more results.
3737 if ( continuation == null || continuation . Count == 0 )
3838 return CONTINUATION_DONE ;
39+
3940 var anyNewValue = false ;
4041 continuationParams ? . Clear ( ) ;
4142 foreach ( var p in continuation )
4243 {
4344 if ( p . Value == null ) continue ;
4445
45- var parsed = p . Value switch
46+ var parsed = p . Value . GetValueKind ( ) switch
4647 {
47- JsonValue value => value . GetValue < object > ( ) ,
48+ // Trivial: unwrap strings.
49+ JsonValueKind . String => p . Value . GetValue < string > ( ) ,
50+ // Retrieve JSON representation so we won't need to consider which int/float type to use.
51+ JsonValueKind . Number => p . Value . ToJsonString ( ) ,
52+ // Ignore nulls.
53+ JsonValueKind . Null or JsonValueKind . Undefined => null ,
54+ // We cannot help -- this is the best we can do.
4855 _ => p . Value . ToJsonString ( ) ,
4956 } ;
50- if ( ! queryParams . TryGetValue ( p . Key , out var existingValue ) || ! ValueEquals ( existingValue , parsed ) )
57+ if ( parsed == null ) continue ;
58+
59+ if ( ! queryParams . TryGetValue ( p . Key , out var existing ) || ! Equals ( existing , parsed ) )
5160 anyNewValue = true ;
61+
5262 continuationParams ? . Add ( new ( p . Key , parsed ) ) ;
5363 }
5464 return anyNewValue ? CONTINUATION_AVAILABLE : CONTINUATION_LOOP ;
55-
56- static bool ValueEquals ( object ? existing , object ? incoming )
57- {
58- if ( Equals ( existing , incoming ) ) return true ;
59- if ( existing is DateTime dt && incoming is string s )
60- {
61- if ( MediaWikiHelper . TryParseDateTime ( s , out var dt2 ) )
62- {
63- // We have called ToUniversalTime() in ToWikiStringValuePairs.
64- return dt . ToUniversalTime ( ) == dt2 . ToUniversalTime ( ) ;
65- }
66- }
67- return false ;
68- }
6965 }
7066
7167 public static JsonNode ? FindQueryResponseItemsRoot ( JsonNode jresult , string actionName )
@@ -115,7 +111,7 @@ public static async IAsyncEnumerable<JsonObject> QueryWithContinuation(WikiSite
115111 // Defensive copy.
116112 var baseQueryParams = new Dictionary < string , object ? > ( parameters ) ;
117113 Debug . Assert ( "query" . Equals ( baseQueryParams [ "action" ] ) ) ;
118- var continuationParams = new Dictionary < string , object ? > ( ) ;
114+ var continuationParams = new Dictionary < string , string > ( ) ;
119115 while ( true )
120116 {
121117 var queryParams = new Dictionary < string , object ? > ( baseQueryParams ) ;
@@ -158,7 +154,7 @@ public static async IAsyncEnumerable<JsonObject> QueryWithContinuation(WikiSite
158154 // Continue the loop and fetch for the next page of query.
159155 break ;
160156 case CONTINUATION_LOOP :
161- throw new UnexpectedDataException ( ) ;
157+ throw new UnexpectedContinuationLoopException ( ) ;
162158 }
163159 }
164160 }
@@ -207,13 +203,13 @@ public static async Task RefreshPagesAsync(IEnumerable<WikiPage> pages, IWikiPag
207203 if ( continuationStatus != CONTINUATION_DONE )
208204 {
209205 var queryParams1 = new Dictionary < string , object ? > ( ) ;
210- var continuationParams = new Dictionary < string , object ? > ( ) ;
206+ var continuationParams = new Dictionary < string , string > ( ) ;
211207 var jobj1 = jobj ;
212208 ParseContinuationParameters ( jobj1 , queryParams1 , continuationParams ) ;
213209 while ( continuationStatus != CONTINUATION_DONE )
214210 {
215211 if ( continuationStatus == CONTINUATION_LOOP )
216- throw new UnexpectedDataException ( Prompts . ExceptionUnexpectedContinuationLoop ) ;
212+ throw new UnexpectedContinuationLoopException ( ) ;
217213 Debug . Assert ( continuationStatus == CONTINUATION_AVAILABLE ) ;
218214 site . Logger . LogDebug ( "Detected query continuation. PartitionCount={PartitionCount}." , partition . Count ) ;
219215 queryParams1 . Clear ( ) ;
0 commit comments