Skip to content

Commit

Permalink
fixed ordering on home
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Aug 9, 2011
1 parent 11da3b3 commit 53cca06
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
21 changes: 19 additions & 2 deletions app.php
Expand Up @@ -444,12 +444,29 @@ function showSaved($name) {
$result = mysql_query($sql);

$bins = array();
$order = array();

// this is lame, but the optimisation was aweful on the joined version - 3-4 second query
// with a full table scan - not good. I'm worried this doesn't scale properly, but I guess
// I could mitigate this with paging on the UI - just a little...?
while ($saved = mysql_fetch_object($result)) {
$sql = sprintf('select * from sandbox where url="%s" and revision="%s"', mysql_real_escape_string($saved->url), mysql_real_escape_string($saved->revision));
$bin = mysql_query($sql);
$binresult = mysql_query($sql);
$bin = mysql_fetch_array($binresult);

$bins[] = mysql_fetch_array($bin);
if (!isset($bins[$saved->url])) {
$bins[$saved->url] = array();
}

$bins[$saved->url][] = $bin;

if (isset($order[$saved->url])) {
if (@strtotime($order[$saved->url]) < @strtotime($bin['created'])) {
$order[$saved->url] = $bin['created'];
}
} else {
$order[$saved->url] = $bin['created'];
}
}

if (count($bins)) {
Expand Down
17 changes: 10 additions & 7 deletions list-home-code.php
Expand Up @@ -189,7 +189,9 @@ function getRelativeTime($date) {
<tbody>
<?php
$last = null;
foreach ($bins as $bin) {
arsort($order);
foreach ($order as $key => $value) {
foreach ($bins[$key] as $bin) {
$url = ROOT . $name . formatURL($bin['url'], $bin['revision']);
preg_match('/<title>(.*?)<\/title>/', $bin['html'], $match);
preg_match('/<body>(.*)/s', $bin['html'], $body);
Expand All @@ -211,15 +213,16 @@ function getRelativeTime($date) {
$firstTime = $bin['url'] != $last;

if ($firstTime && $last !== null) : ?>
<tr data-type="spacer"><td colspan=3></td></tr>
<tr data-type="spacer"><td colspan=3></td></tr>
<?php endif ?>
<tr data-url="<?=$url?>">
<td class="url"><a href="<?=$url?>edit"><span<?=($firstTime ? ' class="first"' : '') . '>' . $bin['url']?>/</span><?=$bin['revision']?>/</a></td>
<td class="created"><a pubdate="<?=$bin['created']?>" href="<?=$url?>edit"><?=getRelativeTime($bin['created'])?></a></td>
<td class="title"><a href="<?=$url?>edit"><?=substr($title, 0, 200)?></a></td>
</tr>
<tr data-url="<?=$url?>">
<td class="url"><a href="<?=$url?>edit"><span<?=($firstTime ? ' class="first"' : '') . '>' . $bin['url']?>/</span><?=$bin['revision']?>/</a></td>
<td class="created"><a pubdate="<?=$bin['created']?>" href="<?=$url?>edit"><?=getRelativeTime($bin['created'])?></a></td>
<td class="title"><a href="<?=$url?>edit"><?=substr($title, 0, 200)?></a></td>
</tr>
<?php
$last = $bin['url'];
}
} ?>
</tbody>
</table>
Expand Down

0 comments on commit 53cca06

Please sign in to comment.