Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing random #1105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Optimizing random #1105

wants to merge 1 commit into from

Conversation

yls4
Copy link
Contributor

@yls4 yls4 commented Mar 11, 2024

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

@discomrade
Copy link
Contributor

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 :)

Comment on lines +232 to +236
if (count($set) > 0) {
return $set;
} else {
return null;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return $set; seems correct here - if there are no results, then an empty array indicates "no results", where null is more like "the concept of results does not exist"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants