avoid rebuilding cache during upload #1190

Open
opened 2026-10-05 00:35:23 +02:00 by adam · 6 comments
Owner

As discussed on https://piwigo.org/forum/viewtopic.php?id=28338 we have a problem on high volume galleries when an upload is running and each photo is uploaded very quickly. The problem comes from the cache regeneration.

In include/user.inc.php we already have:

$user = build_user( $user['id'],
          ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ?
         );

Meaning we avoided to regenerate cache if we were in the administration. That was perfectly valid when we didn't use the API to upload photos. Now that we use pwg.images.upload (and other methods) we skip this IN_ADMIN test and the cache is regenerated each time we call ws.php. We should replace it with something like:

$use_cache = true;
if (defined('IN_ADMIN') and IN_ADMIN)
{
  $use_cache = false;
}

if (isset($_REQUEST['method']) and 'pwg.images.upload' == $_REQUEST['method'])
{
  $use_cache = false;
}

$user = build_user( $user['id'], $use_cache);
As discussed on https://piwigo.org/forum/viewtopic.php?id=28338 we have a problem on high volume galleries when an upload is running and each photo is uploaded very quickly. The problem comes from the cache regeneration. In `include/user.inc.php` we already have: ``` $user = build_user( $user['id'], ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ? ); ``` Meaning we avoided to regenerate cache if we were in the administration. That was perfectly valid when we didn't use the API to upload photos. Now that we use `pwg.images.upload` (and other methods) we skip this `IN_ADMIN` test and the cache is regenerated each time we call `ws.php`. We should replace it with something like: ``` $use_cache = true; if (defined('IN_ADMIN') and IN_ADMIN) { $use_cache = false; } if (isset($_REQUEST['method']) and 'pwg.images.upload' == $_REQUEST['method']) { $use_cache = false; } $user = build_user( $user['id'], $use_cache); ``` <!-- github-sync-id:833021121 -->
Author
Owner

I'm currently testing it on a few Piwigo.com servers :-)

I'm currently testing it on a few Piwigo.com servers :-) <!-- github-comment-id:800444918 -->
Author
Owner

The test shows a problem. During Community upload, the first photo is correctly uploaded, but on next photo:

Warning:  [mysql error 1064] You have an error in your SQL syntax;
    AND level > 8
    AND level <= 8
  GROUP BY category_id' at line 5

SELECT
    category_id
  FROM image_category
    JOIN images ON image_id = id
  WHERE category_id IN ()
    AND level > 8
    AND level <= 8
  GROUP BY category_id
; in include/dblayer/functions_mysqli.inc.php on line 856

The test shows a problem. During Community upload, the first photo is correctly uploaded, but on next photo: ``` Warning: [mysql error 1064] You have an error in your SQL syntax; AND level > 8 AND level <= 8 GROUP BY category_id' at line 5 SELECT category_id FROM image_category JOIN images ON image_id = id WHERE category_id IN () AND level > 8 AND level <= 8 GROUP BY category_id ; in include/dblayer/functions_mysqli.inc.php on line 856 ``` <!-- github-comment-id:801768219 -->
Author
Owner

I don't know how easy it is to do, but, if the website were to use the ws api under the hood, this would have the effect of both having a single code base to test and maintain, and keep the ws api fully featured.

I don't know how easy it is to do, but, if the website were to use the ws api under the hood, this would have the effect of both having a single code base to test and maintain, and keep the ws api fully featured. <!-- github-comment-id:801870752 -->
Author
Owner

I think we need to go deeper on this experiment and try to change Community to keep the idea of not rebuilding cache each time we do a pure admin task like an upload.

I think we need to go deeper on this experiment and try to change Community to keep the idea of not rebuilding cache each time we do a pure admin task like an upload. <!-- github-comment-id:845742180 -->
Author
Owner

With the lounge we already have a nice optimization.

For now and the immediate future, I don't see any easy way to reduce user cache resets. I postpone to 15 the "in depth" brainstorm to make things better.

With the lounge we already have a nice optimization. For now and the immediate future, I don't see any easy way to reduce user cache resets. I postpone to 15 the "in depth" brainstorm to make things better. <!-- github-comment-id:1751684850 -->
Author
Owner

Following #2335 we could have a more comprehensive list of API method that does not trigger user_cache rebuild.

Following #2335 we could have a more comprehensive list of API method that does not trigger user_cache rebuild. <!-- github-comment-id:2692201076 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#1190