This commit is contained in:
Shish 2010-02-02 00:29:38 +00:00
parent 6a75857b72
commit 05150706cc
2 changed files with 21 additions and 13 deletions

View File

@ -49,6 +49,10 @@ class Image {
$this->$name = $value; // hax $this->$name = $value; // hax
} }
$this->posted_timestamp = strtotime($this->posted); // pray $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)); assert(is_array($tags));
global $database; global $database;
if(count($tags) == 0) { 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 { else {
$querylet = Image::build_search_querylet($tags); $querylet = Image::build_search_querylet($tags);
@ -297,10 +307,7 @@ class Image {
* @retval string * @retval string
*/ */
public function get_image_filename() { public function get_image_filename() {
$hash = $this->hash; return warehouse_path("images", $this->hash);
$ab = substr($hash, 0, 2);
$ext = $this->ext;
return "images/$ab/$hash";
} }
/** /**
@ -309,9 +316,7 @@ class Image {
* @retval string * @retval string
*/ */
public function get_thumb_filename() { public function get_thumb_filename() {
$hash = $this->hash; return warehouse_path("thumbs", $this->hash);
$ab = substr($hash, 0, 2);
return "thumbs/$ab/$hash";
} }
/** /**
@ -390,7 +395,7 @@ class Image {
// insert each new tags // insert each new tags
foreach($tags as $tag) { foreach($tags as $tag) {
$id = $database->db->GetOne( $id = $database->db->GetOne(
"SELECT id FROM tags WHERE tag = ?", "SELECT id FROM tags WHERE lower(tag) = lower(?)",
array($tag)); array($tag));
if(empty($id)) { if(empty($id)) {
// a new tag // a new tag
@ -897,10 +902,9 @@ class Tag {
* heirachy, or throw an exception trying * heirachy, or throw an exception trying
*/ */
function move_upload_to_archive($event) { function move_upload_to_archive($event) {
$hash = $event->hash; $target = warehouse_path("images", $event->hash);
$ha = substr($hash, 0, 2); if(!@copy($event->tmpname, $target)) {
if(!@copy($event->tmpname, "images/$ha/$hash")) { throw new UploadException("Failed to copy file from uploads ({$event->tmpname}) to archive ($target)");
throw new UploadException("Failed to copy file from uploads ({$event->tmpname}) to archive (images/$ha/$hash)");
return false; return false;
} }
return true; return true;

View File

@ -465,6 +465,10 @@ function format_text($string) {
return $tfe->formatted; return $tfe->formatted;
} }
function warehouse_path($base, $hash) {
$ab = substr($hash, 0, 2);
return "$base/$ab/$hash";
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Logging convenience * * Logging convenience *