Random thumbnails is not scalable.

I upgraded to 1.1.5 this weekend and noticed how the album thumbnails were constantly changing on every visit - selected on random. With a gallery like mine (~300 albums, >3700 pics) this renders the cache useless, and causes tremendous overhead for the server. The site took several seconds to load every time. :/

My preference is to select the first image from the newest directory; thus updating a gallery thumb only when content has been added (unless I've manually selected a thumb for it). It gives a useful visual clue for visitors and scales a lot better.

The change is simple: open class-album.php and look for the function `getAlbumThumbImage()`. Disable lines 614 (`shuffle($thumbs)`) and 625 (`shuffle($subalbums)`) to do away with random selection, and then change `array_pop` for `array_shift` to select the front-most image of the new album.

Comments

  • Actually, the change is rather more simple. Go to the album edit page and select the thumbnail you want to use. Since you want the first image, it will be at the top of the drop-down list.
  • Manually choosing a thumbnail for every directory I ever upload (and already have uploaded) would get tedious fast.
  • Suit your self. Note, however, that if you change your sort orders you will change your thumbnail. If you want a an album to have a specific thumbnail you need to set it in admin. Otherwise you get one that is arbitrarily selected, either randomly or otherwise.
  • Updating to Zenphoto 1.2 I noticed a change in the default behaviour. ZP Core will now use array_shift (newest image of the album), and only shuffle if no thumbnail has been manually set.

    This doesn't help us that've got hundreds of galleries since before the change, but it does make the hack a lot easier. Instead of what I outlined in the first post, simply change line 655:
    `$shuffle = $thumb != '1';`
    to:
    `$shuffle = false;`
  • With the new change you can use a sql query to set all your album thumbs to '1' and be done with it. That is fairly easy even with thousands of albums.
  • Indeed. Should've thought of that. XD
  • Just updated from trunk and had to resolve this issue once and for all. Here's the query to use if anyone needs it:

    `UPDATE 'albums' SET 'thumb' = 1 WHERE 'thumb' IS NULL;`

    and for good measure (if you've got a few empty lines like I did):

    `UPDATE 'albums' SET 'thumb' = 1 WHERE 'thumb' = '';`
Sign In or Register to comment.