@@ -280,15 +280,58 @@ public async Task<List<ChargePoint>> DeDuplicateList(List<ChargePoint> cpList, b
280280 if ( fetchExistingFromAPI )
281281 {
282282 // fetch from API
283- masterList = await _client . GetPOIListAsync ( new SearchFilters
283+ var modifiedSince = DateTime . MinValue ;
284+
285+ // Fetch all POIs incrementally by ordering by ModifiedSince and updating the last max ModifiedSince
286+ var allPOIs = new List < ChargePoint > ( ) ;
287+ DateTime ? lastModified = null ;
288+ bool moreData = true ;
289+ const int pageSize = 1000 ; // adjust as needed for API limits
290+
291+ do
284292 {
285- CountryIDs = countryIds ,
286- IncludeUserComments = false ,
287- Verbose = false ,
288- MaxResults = 1000000 ,
289- EnableCaching = true ,
290- SubmissionStatusTypeIDs = new int [ 0 ]
291- } ) ;
293+ var searchFilters = new SearchFilters
294+ {
295+ CountryIDs = countryIds ,
296+ IncludeUserComments = false ,
297+ Verbose = false ,
298+ MaxResults = pageSize ,
299+ EnableCaching = true ,
300+ SubmissionStatusTypeIDs = new int [ 0 ] ,
301+ ModifiedSince = lastModified ,
302+ SortBy = "modified_asc"
303+ } ;
304+
305+ var page = ( await _client . GetPOIListAsync ( searchFilters ) ) . OrderBy ( cp => cp . DateLastStatusUpdate ) . ToList ( ) ;
306+
307+ if ( page . Count == 0 )
308+ {
309+ moreData = false ;
310+ }
311+ else
312+ {
313+ foreach ( var cp in page )
314+ {
315+ if ( ! allPOIs . Any ( a => a . ID == cp . ID ) )
316+ {
317+ allPOIs . Add ( cp ) ;
318+ }
319+ }
320+
321+ // Update lastModified to the max DateLastStatusUpdate in this page
322+ var maxModified = page . Max ( cp => cp . DateLastStatusUpdate ) ;
323+ if ( maxModified == lastModified || maxModified == null )
324+ {
325+ moreData = false ;
326+ }
327+ else
328+ {
329+ lastModified = maxModified ;
330+ }
331+ }
332+ } while ( moreData ) ;
333+
334+ masterList = allPOIs ;
292335 }
293336 else
294337 {
0 commit comments