@@ -20,12 +20,7 @@ public static class GetUnityUpdates
2020 public static async Task < List < UnityVersion > > FetchAll ( )
2121 {
2222 var cachedVersions = LoadCachedVersions ( ) ;
23- //Console.WriteLine("cachedVersions: "+ cachedVersions);
24- var latestCachedVersion = cachedVersions . FirstOrDefault ( ) ;
25-
26- //Console.WriteLine("FetchAll "+ latestCachedVersion);
27- var newVersions = await FetchNewVersions ( latestCachedVersion ) ;
28- //Console.WriteLine("newVersions " + newVersions);
23+ var newVersions = await FetchNewVersions ( cachedVersions ) ;
2924
3025 var allVersions = newVersions . Concat ( cachedVersions ) . ToList ( ) ;
3126
@@ -34,8 +29,6 @@ public static async Task<List<UnityVersion>> FetchAll()
3429 SaveCachedVersions ( allVersions ) ;
3530 }
3631
37- //Console.WriteLine("all "+ allVersions);
38-
3932 return allVersions ;
4033 }
4134
@@ -62,7 +55,6 @@ public static async Task<string> FetchDownloadUrl(string unityVersion)
6255
6356 private static async Task < string > ExtractDownloadUrlAsync ( string json , string unityVersion )
6457 {
65-
6658 int resultsIndex = json . IndexOf ( "\" results\" :" ) ;
6759 if ( resultsIndex == - 1 ) return null ;
6860
@@ -122,28 +114,39 @@ private static async Task<bool> CheckAssistantUrl(string assistantUrl)
122114 }
123115 }
124116
125- private static async Task < List < UnityVersion > > FetchNewVersions ( UnityVersion latestCachedVersion )
117+ private static async Task < List < UnityVersion > > FetchNewVersions ( List < UnityVersion > cachedVersions )
126118 {
127119 var newVersions = new List < UnityVersion > ( ) ;
120+ var cachedVersionSet = new HashSet < string > ( cachedVersions . Select ( v => v . Version ) ) ;
128121 int offset = 0 ;
129122 int total = int . MaxValue ;
123+ bool foundNewVersionInBatch ;
130124
131125 while ( offset < total )
132126 {
133127 var batchUpdates = await FetchBatch ( offset ) ;
134- if ( batchUpdates == null || batchUpdates . Count == 0 )
135- break ;
128+ if ( batchUpdates == null || batchUpdates . Count == 0 ) break ;
129+
130+ foundNewVersionInBatch = false ;
136131
137132 foreach ( var version in batchUpdates )
138133 {
139- if ( version . Version == latestCachedVersion ? . Version )
140- return newVersions ;
134+ if ( ! cachedVersionSet . Contains ( version . Version ) )
135+ {
136+ newVersions . Add ( version ) ;
137+ foundNewVersionInBatch = true ;
138+ }
139+ }
141140
142- newVersions . Add ( version ) ;
141+ if ( ! foundNewVersionInBatch )
142+ {
143+ // Exit if no new versions are found in the current batch
144+ break ;
143145 }
144146
145147 offset += batchUpdates . Count ;
146148
149+ // Apply delay if reaching batch limit
147150 if ( offset % ( BatchSize * RequestsPerBatch ) == 0 )
148151 {
149152 await Task . Delay ( DelayBetweenBatches ) ;
@@ -153,6 +156,8 @@ private static async Task<List<UnityVersion>> FetchNewVersions(UnityVersion late
153156 return newVersions ;
154157 }
155158
159+
160+
156161 private static async Task < List < UnityVersion > > FetchBatch ( int offset )
157162 {
158163 string url = $ "{ BaseApiUrl } ?limit={ BatchSize } &offset={ offset } &architecture=X86_64&platform=WINDOWS";
@@ -187,6 +192,7 @@ private static List<UnityVersion> ParseUnityVersions(string json)
187192 ReleaseDate = DateTime . TryParse ( GetStringValue ( item , "releaseDate" ) , out var date ) ? date : default ,
188193 Stream = Enum . TryParse < UnityVersionStream > ( GetStringValue ( item , "stream" ) , true , out var stream ) ? stream : UnityVersionStream . Tech
189194 } ;
195+ //Console.WriteLine(version.Version);
190196 versions . Add ( version ) ;
191197 }
192198 }
0 commit comments