@@ -511,8 +511,7 @@ export async function getAccountLinkingMetrics(
511511 prisma . discordCommandLog . groupBy ( {
512512 by : [ "discordUserId" , "discordUsername" ] ,
513513 where,
514- _count : { _all : true } ,
515- orderBy : { _count : { discordUserId : "desc" } } ,
514+ _count : true ,
516515 } ) ,
517516 prisma . discordCommandLog . findMany ( {
518517 where,
@@ -534,11 +533,12 @@ export async function getAccountLinkingMetrics(
534533
535534 // Find users with multiple requests (repeat requesters)
536535 const repeatRequestUsers = userGroups
537- . filter ( ( u ) => u . _count . _all > 1 )
536+ . filter ( ( u ) => u . _count > 1 )
537+ . sort ( ( a , b ) => b . _count - a . _count )
538538 . map ( ( u ) => ( {
539539 discordUserId : u . discordUserId ,
540540 discordUsername : u . discordUsername ,
541- requestCount : u . _count . _all ,
541+ requestCount : u . _count ,
542542 } ) )
543543
544544 return {
@@ -578,8 +578,7 @@ export async function getMediaMarkingBreakdown(
578578 prisma . discordCommandLog . groupBy ( {
579579 by : [ "commandName" ] ,
580580 where,
581- _count : { _all : true } ,
582- orderBy : { _count : { _all : "desc" } } ,
581+ _count : true ,
583582 } ) ,
584583 prisma . discordCommandLog . findMany ( {
585584 where,
@@ -612,19 +611,21 @@ export async function getMediaMarkingBreakdown(
612611 commandStats . set ( log . commandName , existing )
613612 }
614613
615- const byCommand = commandGroups . map ( ( g ) => {
616- const stats = commandStats . get ( g . commandName ) || {
617- count : 0 ,
618- successCount : 0 ,
619- failedCount : 0 ,
620- }
621- return {
622- commandName : g . commandName ,
623- count : g . _count . _all ,
624- successCount : stats . successCount ,
625- failedCount : stats . failedCount ,
626- }
627- } )
614+ const byCommand = commandGroups
615+ . sort ( ( a , b ) => b . _count - a . _count )
616+ . map ( ( g ) => {
617+ const stats = commandStats . get ( g . commandName ) || {
618+ count : 0 ,
619+ successCount : 0 ,
620+ failedCount : 0 ,
621+ }
622+ return {
623+ commandName : g . commandName ,
624+ count : g . _count ,
625+ successCount : stats . successCount ,
626+ failedCount : stats . failedCount ,
627+ }
628+ } )
628629
629630 // Extract media titles from commandArgs (top 10)
630631 const titleCounts = new Map < string , number > ( )
@@ -678,29 +679,31 @@ export async function getContextMetrics(
678679 prisma . discordCommandLog . groupBy ( {
679680 by : [ "commandName" ] ,
680681 where,
681- _count : { _all : true } ,
682- orderBy : { _count : { _all : "desc" } } ,
682+ _count : true ,
683683 } ) ,
684684 prisma . discordCommandLog . groupBy ( {
685685 by : [ "discordUserId" , "discordUsername" ] ,
686686 where,
687- _count : { _all : true } ,
688- orderBy : { _count : { discordUserId : "desc" } } ,
689- take : 10 ,
687+ _count : true ,
690688 } ) ,
691689 ] )
692690
693691 return {
694692 totalClears,
695- clearsByCommand : commandGroups . map ( ( g ) => ( {
696- commandName : g . commandName ,
697- count : g . _count . _all ,
698- } ) ) ,
699- topClearUsers : userGroups . map ( ( u ) => ( {
700- discordUserId : u . discordUserId ,
701- discordUsername : u . discordUsername ,
702- clearCount : u . _count . _all ,
703- } ) ) ,
693+ clearsByCommand : commandGroups
694+ . sort ( ( a , b ) => b . _count - a . _count )
695+ . map ( ( g ) => ( {
696+ commandName : g . commandName ,
697+ count : g . _count ,
698+ } ) ) ,
699+ topClearUsers : userGroups
700+ . sort ( ( a , b ) => b . _count - a . _count )
701+ . slice ( 0 , 10 )
702+ . map ( ( u ) => ( {
703+ discordUserId : u . discordUserId ,
704+ discordUsername : u . discordUsername ,
705+ clearCount : u . _count ,
706+ } ) ) ,
704707 }
705708}
706709
@@ -735,15 +738,12 @@ export async function getErrorAnalysis(
735738 prisma . discordCommandLog . groupBy ( {
736739 by : [ "commandType" ] ,
737740 where,
738- _count : { _all : true } ,
739- orderBy : { _count : { _all : "desc" } } ,
741+ _count : true ,
740742 } ) ,
741743 prisma . discordCommandLog . groupBy ( {
742744 by : [ "commandName" ] ,
743745 where,
744- _count : { _all : true } ,
745- orderBy : { _count : { _all : "desc" } } ,
746- take : 10 ,
746+ _count : true ,
747747 } ) ,
748748 prisma . discordCommandLog . findMany ( {
749749 where,
@@ -777,15 +777,20 @@ export async function getErrorAnalysis(
777777
778778 return {
779779 totalErrors,
780- errorsByType : typeGroups . map ( ( g ) => ( {
781- commandType : g . commandType ,
782- count : g . _count . _all ,
783- } ) ) ,
784- errorsByCommand : commandGroups . map ( ( g ) => ( {
785- commandName : g . commandName ,
786- count : g . _count . _all ,
787- sampleErrors : errorSamples . get ( g . commandName ) || [ ] ,
788- } ) ) ,
780+ errorsByType : typeGroups
781+ . sort ( ( a , b ) => b . _count - a . _count )
782+ . map ( ( g ) => ( {
783+ commandType : g . commandType ,
784+ count : g . _count ,
785+ } ) ) ,
786+ errorsByCommand : commandGroups
787+ . sort ( ( a , b ) => b . _count - a . _count )
788+ . slice ( 0 , 10 )
789+ . map ( ( g ) => ( {
790+ commandName : g . commandName ,
791+ count : g . _count ,
792+ sampleErrors : errorSamples . get ( g . commandName ) || [ ] ,
793+ } ) ) ,
789794 errorTrend : Array . from ( errorsByDate . entries ( ) ) . map ( ( [ date , count ] ) => ( {
790795 date,
791796 count,
0 commit comments