shimmie2 icon indicating copy to clipboard operation
shimmie2 copied to clipboard

Optimizing random

Open yls4 opened this issue 11 months ago • 1 comments

Using RAND() function to make shuffle work faster. I don't know what other databases are used and if they also have RAND().

yls4 avatar Mar 11 '24 22:03 yls4

I don't know what other databases are used and if they also have RAND().

As listed on the Install documentation, Shimmie currently supports PostgreSQL 14+ / MySQL 8.0+ / SQLite 3.37+.

MySQL has RAND(). PostgreSQL and SQLite don't have RAND(), instead they have RANDOM(). The code will need to check which type of database it is to give the correct random function name. Something like:

if ($database->get_driver_id() == DatabaseDriverID::MYSQL) {
    $order = "RAND()";
} else {
    $order = "RANDOM()";
}

I also noticed all the formatting and static analysis tests are failing too. Use these tools to test your code :)

discomrade avatar May 16 '24 00:05 discomrade