Skip to content

Commit

Permalink
Merge pull request #9 from FynskeMedier/master
Browse files Browse the repository at this point in the history
Fix for dead indexes.
  • Loading branch information
akimsko committed Apr 12, 2013
2 parents 19a2b98 + 7d2dc47 commit 6186b55
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions handlers/test.php
@@ -0,0 +1,4 @@
<?php
require('shutdown.php');
trigger_error("Wazzup from " . exec('hostname -f'));

17 changes: 15 additions & 2 deletions modules/Api/Public/Model/Line.php
Expand Up @@ -350,7 +350,8 @@ public static function getTotal($path = null, $level = null, $handled = false) {
private static function _getByPrefix($prefix, $offset, $limit, $path = null, $level = null, $handled = false) {
$redis = self::_getIndexingRedis();
$start = $offset;
$end = $start + ($limit - 1);
// We fetch more results from redis than we need, in case we need to discard some of them
$end = $start + $limit * 2;

$id = uniqid(self::SEARCH_PREFIX, true);

Expand All @@ -376,7 +377,19 @@ private static function _getByPrefix($prefix, $offset, $limit, $path = null, $le

$result = array();
foreach ($redis->zRevRange($id, $start, $end) as $key) {
$result[] = new ApiPublicModelLine($key);
try {
$modelLine = new ApiPublicModelLine($key);
$result[] = $modelLine;
if (count($result) >= $limit) {
// We don't need any more results
break;
}
} catch (RuntimeException $e) {
// Key not found, remove from indexes
foreach ($zinters as $inter) {
$redis->zRem($inter, $key);
}
}
}

$redis->del($id);
Expand Down

0 comments on commit 6186b55

Please sign in to comment.