Commit 65e60b68 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Page listant les synchros : accélération en calculant simplement l'existence...

Page listant les synchros : accélération en calculant simplement l'existence d'une différence entre source et destination (et non plus le nombre de différences).
parent 6a2d2a8a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -41,12 +41,12 @@ class SynchroController extends AbstractActionController
            $synchros = $this->synchroService->getSynchros();
        }

        $importLogs = $diffCounts = [];
        $importLogs = $diffFounds = [];
        foreach ($synchros as $synchro) {
            $importLog = $this->importLogService->findLastLogForSynchro($synchro);
            $importLogs[$synchro->getName()] = $importLog;
            try{
                $diffCounts[$synchro->getName()] = $this->synchroService->fetchSynchroDiffCount($synchro);
                $diffFounds[$synchro->getName()] = $this->synchroService->fetchSynchroDiffFound($synchro);
            }
            catch (Exception $e){
                $this->flashMessenger()->addErrorMessage(sprintf(
@@ -60,7 +60,7 @@ class SynchroController extends AbstractActionController
        return [
            'synchros' => $synchros,
            'importLogs' => $importLogs,
            'diffCounts' => $diffCounts,
            'diffFounds' => $diffFounds,
            'text' => $text,
        ];
    }
+17 −0
Original line number Diff line number Diff line
@@ -369,6 +369,23 @@ class DatabaseService extends AbstractDatabaseService
        }
    }

    /**
     * @throws \UnicaenDbImport\Service\Exception\DatabaseServiceException
     */
    public function fetchDiffViewFound(): bool
    {
        $sql = $this->codeGenerator->generateSQLForDiffViewSelect($this->source, $this->destination);
        $sql = 'select count(*) as found from (' . $sql . ' limit 1) tmp';

        try {
            $result = $this->queryExecutor->fetch($sql, $this->destination->getConnection());
        } catch (Exception $e) {
            throw DatabaseServiceException::error("Erreur lors de l'interrogation de la vue différentielle ", $e);
        }

        return (bool) (int) $result['found'];
    }

    /**
     * @return int
     * @throws \UnicaenDbImport\Service\Exception\DatabaseServiceException
+34 −0
Original line number Diff line number Diff line
@@ -94,6 +94,40 @@ class SynchroFacadeService extends AbstractFacadeService
        return $result;
    }

    /**
     * @throws \UnicaenDbImport\Service\Exception\DatabaseServiceException
     * @throws \UnicaenDbImport\Service\Exception\ApiServiceException
     */
    public function fetchSynchroDiffFound(): bool
    {
        $intermediateTable = null;

        if ($this->requiresIntermediateTable) {
            $this->fetchSource();
            $intermediateTable = $this->destination->getIntermediateTable();
            if ($this->destination->getIntermediateTableAutoDrop()) {
                $this->logger->info("Suppression de la table intermédiaire $intermediateTable");
                $this->databaseService->dropIntermediateTable($intermediateTable);
            } else {
                $this->databaseService->checkIntermediateTableNotExists($intermediateTable);
            }

            $this->logger->info("Création de la table intermédiaire $intermediateTable");
            $this->databaseService->createIntermediateTable($intermediateTable);
            $this->logger->info("Peuplement de la table intermédiaire $intermediateTable");
            $this->databaseService->populateTableFromSource($intermediateTable);
        }

        $this->recreateDiffView();
        $result = $this->databaseService->fetchDiffViewFound();

        if ($this->requiresIntermediateTable) {
            $this->logger->info("Suppression de la table intermédiaire");
            $this->databaseService->dropIntermediateTable($intermediateTable);
        }
        return $result;
    }

    /**
     * @return int
     * @throws \UnicaenDbImport\Service\Exception\DatabaseServiceException
+20 −0
Original line number Diff line number Diff line
@@ -177,6 +177,26 @@ class SynchroService
        }
    }

    /**
     * @param \UnicaenDbImport\Domain\SynchroInterface $synchro
     * @return bool
     */
    public function fetchSynchroDiffFound(SynchroInterface $synchro): bool
    {
        $this->synchroFacadeService->setSynchro($synchro);

        try {
            $this->synchroFacadeService->validateDestination();
            $this->synchroFacadeService->validateSource();
            $this->synchroFacadeService->discoverSourceColumns();

            return $this->synchroFacadeService->fetchSynchroDiffFound();

        } catch (Exception $e) {
            throw new RuntimeException("Erreur rencontrée : " . $e->getMessage(), null, $e);
        }
    }

    /**
     * @param \UnicaenDbImport\Domain\SynchroInterface $synchro
     * @return int
+6 −6
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
/**
 * @var \UnicaenDbImport\Domain\Synchro[] $synchros
 * @var \UnicaenDbImport\Entity\Db\ImportLog[] $importLogs
 * @var int[] $diffCounts
 * @var int[] $diffFounds
 * @var string $text
 * @var \Application\View\Renderer\PhpRenderer $this
 *
@@ -63,7 +63,7 @@ $lancable = $this->isAllowed(SynchroPrivilege::getResourceId(SynchroPrivilege::L
                <?php echo $this->translate("Dernier log"); ?>
            </th>
            <th rowspan="2">
                <?php echo $this->translate("Diff"); ?>
                <?php echo $this->translate("Diff"); ?> ?
            </th>
        </tr>
        <tr>
@@ -91,7 +91,7 @@ $lancable = $this->isAllowed(SynchroPrivilege::getResourceId(SynchroPrivilege::L
            $source = $synchro->getSource();
            $destination = $synchro->getDestination();
            $importLog = $importLogs[$synchro->getName()] ?? null;
            $diffCount = $diffCounts[$synchro->getName()] ?? 0;
            $diffFound = $diffFounds[$synchro->getName()] ?? 0;
            ?>
            <tr class="synchro">
                <td>
@@ -134,7 +134,7 @@ $lancable = $this->isAllowed(SynchroPrivilege::getResourceId(SynchroPrivilege::L
                    <?php endif ?>
                </td>
                <td class="diff">
                    <?php if ($diffCount): ?>
                    <?php if ($diffFound): ?>
                        <?php if ($lancable): ?>
                            <a class="btn btn-warning btn-sm"
                               title="Lancer la synchro"
@@ -146,10 +146,10 @@ $lancable = $this->isAllowed(SynchroPrivilege::getResourceId(SynchroPrivilege::L
                        <?php endif ?>
                        <a href="<?php echo $this->url('unicaen-db-import/synchro/diff', ['name' => $synchro->getName()]) ?>"
                           title="Voir le différentiel">
                            <?php echo $diffCount ?>
                            Oui
                        </a>
                    <?php else: ?>
                        -
                        Non
                    <?php endif ?>
                </td>
            </tr>