Commit a90ee188 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Optimisation des tries pour les recherches sur les personnes

parent 89e7bdee
Loading
Loading
Loading
Loading
+4 −0
Changes for module/Oscar/src/Oscar/Service/OrganizationService.php: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -317,9 +317,13 @@ class OrganizationService implements ServiceLocatorAwareInterface, EntityManager
        }

        if( count($ids) ){
            // On ne trie que les 30 premiers
            $limit = 30;
            $nbr = 0;
            $case = '(CASE ';
            $i = 0;
            foreach ($ids as $id) {
                if( $nbr++ < $limit )
                    $case .= sprintf('WHEN o.id = \'%s\' THEN %s ', $id, $i++);
            }
            $case .= " ELSE $id END) AS HIDDEN ORD";
+16 −0
Changes for module/Oscar/src/Oscar/Service/PersonService.php: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -875,9 +875,25 @@ class PersonService implements ServiceLocatorAwareInterface, EntityManagerAwareI
                ->setParameter(':ids', $ids);
        }



        if( array_key_exists('ids', $filters) ){
            $query->andWhere('p.id IN(:filterIds)')
                ->setParameter('filterIds', $filters['ids']);

            if( $search && count($filters['ids']) > 0 ){
                // On ne trie que les 30 premiers
                $limit = 30;
                $case = '(CASE ';
                $i = 0;
                foreach ($filters['ids'] as $id) {
                    if( $i++ < $limit )
                        $case .= sprintf('WHEN p.id = \'%s\' THEN %s ', $id, $i++);
                }
                $case .= " ELSE $id END) AS HIDDEN ORD";
                $query->addSelect($case);
                $query->orderBy("ORD", 'ASC');
            }
        }

//        var_dump($query->getDQL()); die();