diff options
author | Andy Staudacher <andy.st@gmail.com> | 2010-02-07 22:30:08 -0800 |
---|---|---|
committer | Andy Staudacher <andy.st@gmail.com> | 2010-02-07 22:30:08 -0800 |
commit | 0a6630af2d63add9b31e382e46e8922f5845d361 (patch) | |
tree | 14f160228aaf3282a5ba7222d1dc19684959b9f8 /modules | |
parent | bca3eeb92399093214ac0f5a74a380b14ffd0405 (diff) |
Improve likelihood that image block shows up for small photo collections by retrying the random query a few times.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/image_block/helpers/image_block_block.php | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/modules/image_block/helpers/image_block_block.php b/modules/image_block/helpers/image_block_block.php index 185df850..82c92f19 100644 --- a/modules/image_block/helpers/image_block_block.php +++ b/modules/image_block/helpers/image_block_block.php @@ -26,7 +26,13 @@ class image_block_block_Core { $block = ""; switch ($block_id) { case "random_image": - $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current(); + // The random_query approach is flawed and doesn't always return a + // result when there actually is one. Retry a *few* times. + // @todo Consider another fallback if further optimizations are necessary. + $attempts = 0; + do { + $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current(); + } while (!$item && $attempts++ < 3); if ($item && $item->loaded()) { $block = new Block(); $block->css_id = "g-image-block"; |