@@ -198,7 +198,7 @@ public async Task<IActionResult> OnPostAsync()
198198 }
199199 }
200200
201- var slugProjects = await TryToFindSlug ( ProjectSearchField ) ;
201+ var slugProjects = await SharedMethods . TryToFindSlug ( _redis , _cfApiClient , ProjectSearchField ) ;
202202 if ( slugProjects . Count == 0 )
203203 {
204204 ErrorMessage = "You need to enter a valid project id or slug to lookup the project. (We found nothing)" ;
@@ -239,7 +239,6 @@ public async Task<IActionResult> OnPostAsync()
239239
240240 FoundMod = await SharedMethods . SearchModAsync ( _redis , _cfApiClient , projectId ) ;
241241
242-
243242 if ( FoundMod == null )
244243 {
245244 ErrorMessage = "Could not find the project" ;
@@ -253,62 +252,6 @@ public async Task<IActionResult> OnPostAsync()
253252 return Page ( ) ;
254253 }
255254
256- private async Task < ConcurrentDictionary < string , ( Game game , Category category , List < Mod > mods ) > > TryToFindSlug ( string slug )
257- {
258- var returnValue = new ConcurrentDictionary < string , ( Game game , Category category , List < Mod > mods ) > ( ) ;
259- var gameClasses = new ConcurrentDictionary < Game , List < Category > > ( ) ;
260- var games = await SharedMethods . GetGameInfo ( _redis , _cfApiClient ) ;
261-
262- var gameClassTasks = games . Select ( async game =>
263- {
264- var classes = ( await SharedMethods . GetCategoryInfo ( _redis , _cfApiClient , game . Id ) ) . Where ( c => c . IsClass ?? false ) . ToList ( ) ?? new List < Category > ( ) ;
265- gameClasses . TryAdd ( game , classes ) ;
266- } ) ;
267-
268- await Task . WhenAll ( gameClassTasks ) ;
269-
270- var sortedList = gameClasses . OrderByDescending ( c => c . Key . Id == 432 || c . Key . Id == 1 ) ;
271-
272- var cachedSlugSearch = await _redis . StringGetAsync ( $ "cf-slug-search-{ slug } ") ;
273-
274- if ( ! cachedSlugSearch . IsNullOrEmpty )
275- {
276- return JsonConvert . DeserializeObject < ConcurrentDictionary < string , ( Game game , Category category , List < Mod > mods ) > > ( cachedSlugSearch ) ;
277- }
278-
279- var keyTasks = sortedList . Select ( async kv =>
280- {
281- var gameCategoryTasks = kv . Value . Select ( async cat =>
282- {
283- try
284- {
285- var modSearch = await _cfApiClient . SearchModsAsync ( kv . Key . Id , cat . Id , slug : slug ) ;
286- if ( modSearch . Data . Count > 0 )
287- {
288- if ( ! returnValue . ContainsKey ( $ "{ kv . Key . Id } -{ cat . Id } ") )
289- {
290- returnValue . TryAdd ( $ "{ kv . Key . Id } -{ cat . Id } ", ( kv . Key , cat , new List < Mod > ( ) ) ) ;
291- }
292-
293- returnValue [ $ "{ kv . Key . Id } -{ cat . Id } "] . mods . AddRange ( modSearch . Data ) ;
294- }
295- }
296- catch
297- {
298- // Empty, because.. yeah
299- }
300- } ) ;
301-
302- await Task . WhenAll ( gameCategoryTasks ) ;
303- } ) ;
304-
305- await Task . WhenAll ( keyTasks ) ;
306-
307- await _redis . StringSetAsync ( $ "cf-slug-search-{ slug } ", JsonConvert . SerializeObject ( returnValue ) , TimeSpan . FromMinutes ( 5 ) ) ;
308-
309- return returnValue ;
310- }
311-
312255 private async Task < string > GetProjectNameFromFile ( string url )
313256 {
314257 return Path . GetFileName ( url ) ;
0 commit comments