From 05150706cc9a88a1586f0a7ad42f29230d152d12 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 2 Feb 2010 00:29:38 +0000 Subject: [PATCH] wtf git --- core/imageboard.pack.php | 30 +++++++++++++++++------------- core/util.inc.php | 4 ++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 964167d4..c4c39fb5 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -49,6 +49,10 @@ class Image { $this->$name = $value; // hax } $this->posted_timestamp = strtotime($this->posted); // pray + + assert(is_numeric($this->id)); + assert(is_numeric($this->height)); + assert(is_numeric($this->width)); } } @@ -128,7 +132,13 @@ class Image { assert(is_array($tags)); global $database; if(count($tags) == 0) { - return $database->db->GetOne("SELECT COUNT(*) FROM images"); + #return $database->db->GetOne("SELECT COUNT(*) FROM images"); + $total = $database->cache->get("image-count"); + if(!$total) { + $total = $database->db->GetOne("SELECT COUNT(*) FROM images"); + $database->cache->set("image-count", $total, 600); + } + return $total; } else { $querylet = Image::build_search_querylet($tags); @@ -297,10 +307,7 @@ class Image { * @retval string */ public function get_image_filename() { - $hash = $this->hash; - $ab = substr($hash, 0, 2); - $ext = $this->ext; - return "images/$ab/$hash"; + return warehouse_path("images", $this->hash); } /** @@ -309,9 +316,7 @@ class Image { * @retval string */ public function get_thumb_filename() { - $hash = $this->hash; - $ab = substr($hash, 0, 2); - return "thumbs/$ab/$hash"; + return warehouse_path("thumbs", $this->hash); } /** @@ -390,7 +395,7 @@ class Image { // insert each new tags foreach($tags as $tag) { $id = $database->db->GetOne( - "SELECT id FROM tags WHERE tag = ?", + "SELECT id FROM tags WHERE lower(tag) = lower(?)", array($tag)); if(empty($id)) { // a new tag @@ -897,10 +902,9 @@ class Tag { * heirachy, or throw an exception trying */ function move_upload_to_archive($event) { - $hash = $event->hash; - $ha = substr($hash, 0, 2); - if(!@copy($event->tmpname, "images/$ha/$hash")) { - throw new UploadException("Failed to copy file from uploads ({$event->tmpname}) to archive (images/$ha/$hash)"); + $target = warehouse_path("images", $event->hash); + if(!@copy($event->tmpname, $target)) { + throw new UploadException("Failed to copy file from uploads ({$event->tmpname}) to archive ($target)"); return false; } return true; diff --git a/core/util.inc.php b/core/util.inc.php index 10169dc2..61425789 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -465,6 +465,10 @@ function format_text($string) { return $tfe->formatted; } +function warehouse_path($base, $hash) { + $ab = substr($hash, 0, 2); + return "$base/$ab/$hash"; +} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Logging convenience *