Unnecessary calls to DB for user data

Dax

Core license
License owner
▶🚶‍Reproduction steps
  1. View the DB queries for viewing a userpage.
  2. Note that every image causes a additional DB query on the user table and login table.
😢Unexpected result

Line 853 of app/lib/classes/class.listing.php sets $requester to the user ID then passes it to the render function, which will then load the user and login data from the DB recursively. Simply passing the user array instead prevents this. Patch below.

Patch:
--- a/class.listing.php    2019-07-27 01:56:06.692832669 +0100
+++ b/class.listing.php    2019-07-27 01:56:22.379951294 +0100
@@ -850,7 +850,7 @@
                 $render = 'CHV\Render\get_peafowl_item_list';
             }
 
-            $requester = Login::getUser()['id'];
+            $requester = Login::getUser();
 
             $html_output .= $render($tpl_list, $item, $list_item_template, $requester, $tools);
         }
 

Dax

Core license
License owner
There's another one in app/lib/classes/class.user.php::getAlbums()

Patch:
--- a/class.user.php    2019-07-28 00:53:47.547435618 +0100
+++ b/class.user.php    2019-07-28 00:54:10.813612131 +0100
@@ -90,7 +90,7 @@
             $user_albums = [];
 
             // Build the user stream
-            $user_stream = self::getStreamAlbum($id);
+            $user_stream = self::getStreamAlbum($var);
 
             if (is_array($user_stream)) {
                 $user_albums['stream'] = $user_stream;
 

Dax

Core license
License owner
And another two in app/lib/routes/route.user.php
Patch:
--- a/route.user.php    2019-07-28 01:04:41.114394245 +0100
+++ b/route.user.php    2019-07-28 01:07:54.704863000 +0100
@@ -156,7 +156,7 @@

         $handler::setCond('show_follow_button', $show_follow_button);

-        $albums = CHV\User::getAlbums($user["id"]);
+        $albums = CHV\User::getAlbums($user);

         $pre_doctitle = $user['name'];
         if (CHV\getSetting('website_mode') == 'community' or $user['id'] !== CHV\getSetting('website_mode_personal_uid')) {
@@ -373,7 +373,7 @@

         if ($handler::getCond('content_manager') or $is_owner) {
             $handler::setVar('user_items_editor', [
-                "user_albums"    => CHV\User::getAlbums($user["id"]),
+                "user_albums"    => CHV\User::getAlbums($user),
                 "type"            => $user_views['albums']['current'] ? "albums": "images"
             ]);
         }
 

Dax

Core license
License owner
HI,@Dax CAN DOWNLOAD THE FILE ENTIRELY WITH THE MODIFICATION. THANK YOU
Are you asking me to provide a pre-patched copy of Chevereto? If you are then I'm afraid the answer is no as I don't think @Rodolfo would appreciate that, also it'd contain my license key.

The edits are trivial to make, you should easily be able to modify a zip for yourself.
 

Youssef

Network license
License owner
but you did not understand me at all. I already have a chevereto license. I only ask for the file you modified
 
Top