Skip to content

Loading main page (not logged in) generate unnecessary request to github/slows everything down #147

Description

@JabLuszko

As titles states - loading main page as not logged in can be very slow - depending how fast GitHub answers 404 ;')

index.php includes header.php that includes functions.php that includes cache_handler.php and that one tries to load pokemonNames/itemNames. Only problem is both local and remote uses $locale as part of path and because $locale is empty it's testing non-existing files and then trying to download non-existed files (fe. fopen(https://raw.githubusercontent.com/WatWowMap/pogo-translations/master/static/englishRef/pokemon_.json): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found)

$locale is get via session $locale = @$_SESSION['locale']; and set in set_locale()

function set_locale() {
global $conn;
if (isset($_SESSION['id'])) {
include_once "./config.php";
include_once "./include/db_connect.php";
$sql = "select language FROM humans WHERE id = '" . $_SESSION['id'] . "'";
$result = $conn->query($sql) or die(mysqli_error($conn));
while ($row = $result->fetch_assoc()) {
if ( $row['language'] <> "" ) {
$_SESSION['locale'] = $row['language'];
} else {
$_SESSION['locale'] = $_SESSION['server_locale'];
}
}
}
}
but only if $_SESSION['id'] exists - so not logged in users will have no locales at all.

Possible solutions:
Set $_SESSION['locale'] for not logged in users as default (?) one?
Force $locale as "en" if empty in cache_handler.php?
Don't include cache_handler.php at all if user not logged in - is there anything need to render main login page?

Are there other parts of code depending on not set at all $_SESSION['locale']?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions