diff options
author | chris <chris@jalakai.co.uk> | 2006-09-24 18:21:05 +0200 |
---|---|---|
committer | chris <chris@jalakai.co.uk> | 2006-09-24 18:21:05 +0200 |
commit | 27fbc76105241574d75bf28e31676c4801a55ea9 (patch) | |
tree | 4e80553fd0b332f64eb475afe532174a6eef501b /lib | |
parent | b2a412b0811b6d7fc402255e208b043ea95b79de (diff) | |
download | rpg-27fbc76105241574d75bf28e31676c4801a55ea9.tar.gz rpg-27fbc76105241574d75bf28e31676c4801a55ea9.tar.bz2 |
update to previous changes cache patch
- fix potential array key collisions
- restore ability to keep a minimum number ($conf['recent']) of recent changes
irregardless of date of change
darcs-hash:20060924162105-9b6ab-06350f04f9d9ac4c362f13787b682ef70887a1fc.gz
Diffstat (limited to 'lib')
-rw-r--r-- | lib/exe/indexer.php | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index cfbd4ba4b..224c54311 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -62,7 +62,6 @@ function runTrimRecentChanges() { if (@file_exists($conf['changelog']) && (filectime($conf['changelog'])+86400)<time() && !@file_exists($conf['changelog'].'_tmp')) { - io_lock($conf['changelog']); $lines = file($conf['changelog']); if (count($lines)<$conf['recent']) { @@ -71,19 +70,27 @@ function runTrimRecentChanges() { return true; } - io_saveFile($conf['changelog'].'_tmp', ''); // presave tmp as 2nd lock + io_saveFile($conf['changelog'].'_tmp', ''); // presave tmp as 2nd lock $trim_time = time() - $conf['recent_days']*86400; $out_lines = array(); for ($i=0; $i<count($lines); $i++) { $log = parseChangelogLine($lines[$i]); - if ($log === false || $log['date'] < $trim_time) continue; // discard old lines - $out_lines[$log['date']] = $lines[$i]; // preserve the rest + if ($log === false) continue; // discard junk + if ($log['date'] < $trim_time) { + $old_lines[$log['date'].".$i"] = $lines[$i]; // keep old lines for now (append .$i to prevent key collisions) + } else { + $out_lines[$log['date'].".$i"] = $lines[$i]; // definitely keep these lines + } } - ksort($out_lines); // sort lines, just in case! - if (count($out_lines) > $conf['recent']) { - $out_lines = array_slice($out_lines,-$conf['recent']); // trim list to one page + // sort the final result, it shouldn't be necessary, + // however the extra robustness in making the changelog cache self-correcting is worth it + ksort($out_lines); + $extra = $conf['recent'] - count($out_lines); // do we need extra lines do bring us up to minimum + if ($extra > 0) { + ksort($old_lines); + $out_lines = array_merge(array_slice($old_lines,-$extra),$out_lines); } // save trimmed changelog |