@@ -33,8 +33,11 @@ import {
3333 reconcileLocalTagPB ,
3434 saveLocalTagPB ,
3535 __nonReactive as tagsNonReactive ,
36+ useActiveTagsLiveQuery ,
3637} from "./tags" ;
3738import { applyIdWorkaround } from "./utils/misc" ;
39+ import { getConfig } from "../config/store" ;
40+ import { getMode2 } from "../utils/misc" ;
3841
3942export type ResultsQueryState = {
4043 difficulty : SnapshotResult < Mode > [ "difficulty" ] [ ] ;
@@ -550,14 +553,29 @@ export type CurrentSettingsFilter = {
550553} ;
551554
552555// oxlint-disable-next-line typescript/explicit-function-return-type
553- export function useUserAverage10LiveQuery ( options : CurrentSettingsFilter ) {
556+ export function useUserAverage10LiveQuery ( ) {
557+ const tags = useActiveTagsLiveQuery ( ) ;
558+
554559 return useLiveQuery ( ( q ) =>
555560 q
556561 . from ( {
557562 //we use sub-query to filter first and then aggregate
558- last10 : buildSettingsResultsQuery ( options , {
559- tagIds : tagsNonReactive . getActiveTags ( ) . map ( ( it ) => it . _id ) ,
560- } )
563+ last10 : q
564+ . from ( { r : resultsCollection } )
565+ . where ( ( { r } ) => eq ( r . mode , getConfig . mode ) )
566+ . where ( ( { r } ) => eq ( r . mode2 , getMode2 ( getConfig , null ) ) ) //TODO read the current quote without creating a circle
567+ . where ( ( { r } ) => eq ( r . punctuation , getConfig . punctuation ) )
568+ . where ( ( { r } ) => eq ( r . numbers , getConfig . numbers ) )
569+ . where ( ( { r } ) => eq ( r . language , getConfig . language ) )
570+ . where ( ( { r } ) => eq ( r . difficulty , getConfig . difficulty ) )
571+ . where ( ( { r } ) => eq ( r . lazyMode , getConfig . lazyMode ) )
572+ . where ( ( { r } ) =>
573+ or (
574+ false ,
575+ tags ( ) . length === 0 ,
576+ ...tags ( ) . map ( ( it ) => inArray ( it . _id , r . tags ) ) ,
577+ ) ,
578+ )
561579 . orderBy ( ( { r } ) => r . timestamp , "desc" )
562580 . limit ( 10 ) ,
563581 } )
0 commit comments