Commit ce52f2ac authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Changement de strategie pour le refresh

parent b9bdbfec
Loading
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ return [
                    'action' => [
                        'afficher',
                        'rafraichir',
                        'rafraichir-tous-les-indicateurs',
                        'exporter',
                        'regenerer',
                    ],
@@ -110,6 +111,17 @@ return [
                        ],
                        'may_terminate' => true,
                    ],
                    'rafraichir-tous-les-indicateurs' => [
                        'type'  => Literal::class,
                        'options' => [
                            'route'    => '/rafraichir-tous-les-indicateurs',
                            'defaults' => [
                                /** @see IndicateurController::rafraichirTousLesIndicateursAction() */
                                'action'     => 'rafraichir-tous-les-indicateurs',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'regenerer' => [
                        'type'  => Segment::class,
                        'options' => [
+11 −8
Original line number Diff line number Diff line
@@ -83,6 +83,17 @@ class IndicateurController extends AbstractActionController {
        ]);
    }

    public function rafraichirTousLesIndicateursAction() : Response
    {
        $indicateurs = $this->getIndicateurService()->getIndicateurs();

        foreach ($indicateurs as $indicateur) {
            $this->getIndicateurService()->refresh($indicateur);
        }
        /** @see IndicateurController::indexAction()  */
        return $this->redirect()->toRoute('indicateurs', [], [], true);
    }

    public function rafraichirAction() : Response
    {
        $indicateur = $this->getIndicateurService()->getRequestedIndicateur($this);
@@ -227,12 +238,4 @@ class IndicateurController extends AbstractActionController {
        return $CSV;
    }

    public function rafraichirTousAction() : void
    {
        $indicateurs = $this->getIndicateurService()->getIndicateurs();
        foreach ($indicateurs as $indicateur) {
            $this->getIndicateurService()->refresh($indicateur);
        }
    }

}
 No newline at end of file
+9 −3
Original line number Diff line number Diff line
@@ -130,12 +130,17 @@ class IndicateurService
    }

    /**
     * Note : il vaut mieux détruire et reconstruire car si il y a un écart en les données et la requête alors le
     * refresh ne fait pas le nécessaire
     *
     * @param Indicateur $indicateur
     */
    public function refresh(Indicateur $indicateur): void
    {
        $sql = "REFRESH MATERIALIZED VIEW " . $indicateur->getViewId();
        $this->manipulateDatabaseView($sql);
        //$sql = "REFRESH MATERIALIZED VIEW " . $indicateur->getViewId();
        //$this->manipulateDatabaseView($sql);
        $this->dropView($indicateur);
        $this->createView($indicateur);
        $indicateur->setDernierRafraichissement(new DateTime());
        $count = $this->getCount($indicateur);
        $indicateur->setNbElements($count);
@@ -344,8 +349,9 @@ class IndicateurService
        $exist = $this->verifierExistanceMaterializedView($indicateur->getViewId());
        if (!$exist) return null;

        $userPerimetre = $this->extractPerimetres($perimetres);
        $userPerimetre = $perimetres?$this->extractPerimetres($perimetres):null;
        $rawdata = $this->fetch($indicateur, $userPerimetre);
        $rawdata = $this->fetch($indicateur);
        return count($rawdata);
    }

+9 −0
Original line number Diff line number Diff line
@@ -60,6 +60,15 @@ $canAfficherTous = $this->isAllowed(IndicateurPrivileges::getResourceId(Indicate
            Créer un nouvel indicateur
        </a>

        <?php /** @see IndicateurController::rafraichirTousLesIndicateursAction() */?>
        <a href="<?php echo $this->url("indicateur/rafraichir-tous-les-indicateurs", [], [], true); ?>"
           class="btn btn-primary"
        >
            <span class="icon icon-refresh"></span>
            Rafraîchir tous les indicateurs
        </a>


        <?php /** @see AbonnementController::notifierAction() */?>
        <a href="<?php echo $this->url("abonnement/notifier", [], [], true); ?>"
           class="btn btn-primary"