perftools / xhgui

Web interface for XHProf profiling data can store data in MongoDB or PDO database
1.65k stars 341 forks source link

Replace sql type TEXT by LONGTEXT for profile field when using mysql … #487

Closed Mmasson-01 closed 1 year ago

Mmasson-01 commented 1 year ago

Problem

mysql driver truncate data when using field type TEXT while exceeding 65535 characters

Solution

Use field type LONGTEXT when using mysql driver.

Related PR

Alternative

I believe it could add a nice touch to implement an abstract class as a Driver helper. Something like this:

<?php

namespace XHGui\Db;

abstract class PdoDriverAbstract 
{
    /* @var PdoDriverAbstract */
    private $driver;

    public function __construct(string $driverName) 
    {
        switch($driverName)
        {
            case "mysql":
                $this->driver = new PdoMysqlDriver();
                break;
            default:
                $this->driver = new PdoSqliteDriver();
        }

    }

    abstract public function getTableQuery(): string;
}

Then we could do something like this:

 public function __construct(PDO $pdo, string $driverName, string $table, string $tableWatch)
    {
        $this->pdo = $pdo;
        $this->driver = new PdoDriverAbstract($driverName);
        $this->table = sprintf('"%s"', $table);
        $this->tableWatches = sprintf('"%s"', $tableWatch);
        $this->initSchema();
    }

 public function initSchema(): void
    {
            $this->pdo->exec($this->driver->getTableQuery()
                ', $this->table));
   ...
}

It would be ready to scale if other exception happens in the futur...but then its a bit overkill for now.

Let me know !

glensc commented 1 year ago

Maybe less copy paste, and create $profileColumnType = "LONGTEXT" and use that in expression?

Mmasson-01 commented 1 year ago

@glensc Agreed. Let me fix this real quick Meanwhile, what about my alternative suggestion ?