Unnecessary Query

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Unnecessary Query

      Creo que existe una consulta en Session.class.php que puede ser innecesaria yo he hecho algunas pruebas y todo me funciona correctamente, se trata de que se puede evitar una consulta a la base de datos sustituyendo:

      en Session.class.php se puede reemplazar

      PHP Source Code

      1. public function selectActivePlanet()
      2. {
      3. $httpData = HTTP::_GP('cp', 0);
      4. if(!empty($httpData))
      5. {
      6. $sql = 'SELECT id FROM %%PLANETS%% WHERE id = :planetId AND id_owner = :userId;';
      7. $db = Database::get();
      8. $planetId = $db->selectSingle($sql, array(
      9. ':userId' => $this->data['userId'],
      10. ':planetId' => $httpData,
      11. ), 'id');
      12. if(!empty($planetId))
      13. {
      14. $this->data['planetId'] = $planetId;
      15. }
      16. }
      17. }
      Display All



      por:


      PHP Source Code

      1. public function selectActivePlanet()
      2. {
      3. $httpData = HTTP::_GP('cp', 0);
      4. if (!empty($httpData)) {
      5. $this->data['planetId'] = $httpData;
      6. }
      7. }
      y entonces en common.php se remplaza:



      PHP Source Code

      1. if(empty($PLANET))
      2. {
      3. $sql = "SELECT * FROM %%PLANETS%% WHERE id = :planetId;";
      4. $PLANET = $db->selectSingle($sql, array(
      5. ':planetId' => $USER['id_planet'],
      6. ));
      7. if(empty($PLANET))
      8. {
      9. throw new Exception("Main Planet does not exist!");
      10. }
      11. else
      12. {
      13. $session->planetId = $USER['id_planet'];
      14. }
      15. }
      Display All
      por:



      PHP Source Code

      1. if(empty($PLANET) || $PLANET['id_owner'] !== $USER['id'])
      2. {
      3. $sql = "SELECT * FROM %%PLANETS%% WHERE id = :planetId;";
      4. $PLANET = $db->selectSingle($sql, array(
      5. ':planetId' => $USER['id_planet'],
      6. ));
      7. if(empty($PLANET))
      8. {
      9. throw new Exception("Main Planet does not exist!");
      10. }
      11. else
      12. {
      13. $session->planetId = $USER['id_planet'];
      14. }
      15. }
      Display All
      Yo lo he probado y hasta el momento no me ha dado problemas. Si les es útil este Post no olvides suscribirte y dejarnos un like :thumbsup: :thumbsup: :thumbsup: :thumbsup: