XF 2.2 How can I correctly update pruneImageCache with a larger fetch limit?

Fullmental

Active member
We had to adjust the pruneImageCache function in /XF/Repository/ImageProxy.php due to a storage runaway situation with the standard 2,000 fetch limit. We upped it to 20,000 and that seems to be working, but it also causes the file health check to report unexpected contents (understandably so).

If we wanted to make this change "permanent" and tell XF to stop reporting this specific adjustment as unexpected, how can we do so? I don't want us to get accustomed to seeing constant file health check errors in case there is a genuine issue one day.

1732033522320.webp
 
You could generate a new hash and update the check file but every time you update you would have to do it again.
I see, that would be undesirable, but better than nothing.

I realize this is not addon development help, but let's say I wanted to do this. I am not particularly well versed in developing add-ons but I have an extremely basic understanding of the structure. Is the correct way to simply extend /XF/Repository/ImageCache.php and rewrite the desired function in the addon files? Or is it more complicated than that?
 
If anyone finds this later and needs to do the same, I was indeed able to override the function with a single class extension that duplicates the pruneImageCache function and changes the fetch value to 10000. I then validated with SELECT SUM(pruned) FROM `xf_image_proxy` to confirm the pruned count was increasing by 10,000 every time I manually ran the hourly clean up cron job:

Code:
<?php

namespace NuzForums\ImgProxyPrune\XF\Repository;

class ImageProxy extends XFCP_ImageProxy
{
       /**
     * Prunes images from the file system cache that have expired
     *
     * @param integer|null $pruneDate
     */
    public function pruneImageCache($pruneDate = null)
    {
        if ($pruneDate === null)
        {
            if (!$this->options()->imageCacheTTL)
            {
                return;
            }

            $pruneDate = \XF::$time - (86400 * $this->options()->imageCacheTTL);
        }

        /** @var \XF\Entity\ImageProxy[] $images */
        $images = $this->finder('XF:ImageProxy')
            ->where('fetch_date', '<', $pruneDate)
            ->where('pruned', 0)
            ->where('is_processing', 0)
            ->fetch(10000);
        foreach ($images AS $image)
        {
            $image->prune();
        }
    }
}

A single class extension in the ACP was all that was needed:

1732504026770.webp

No guarantees it is bug free, but I mean it shouldn't cause any errors given I'm literally only changing a fetch value here.
 
Back
Top Bottom