[misc] Add a vastly more efficient way to display random photos.
This commit is contained in:
parent
a7bde851c6
commit
6f4e4c952d
1
CHANGES
1
CHANGES
|
@ -34,6 +34,7 @@ For further information about Photo Organizer, see its web site at:
|
|||
[misc] Migrate more queries to take advantage of memcache.
|
||||
[fix] Allow guests/etc to see technical image details.
|
||||
[misc] Consolidated photo and version import into one function.
|
||||
[misc] Added a vastly more efficient way of fetching random photos.
|
||||
|
||||
2.36.1 (September 27, 2008)
|
||||
|
||||
|
|
|
@ -584,8 +584,11 @@ function site_display_photo($database, $identifier, $framed, $version = FALSE) {
|
|||
}
|
||||
|
||||
function site_get_photos($database, $type, $identifier, $num_of_photos, $order) {
|
||||
$sql_extra_tables = array();
|
||||
global $po_user;
|
||||
global $passwords;
|
||||
|
||||
$sql_extra_tables = array();
|
||||
|
||||
switch ($type) {
|
||||
case "photo":
|
||||
$parts = explode(":", $identifier);
|
||||
|
@ -599,7 +602,12 @@ function site_get_photos($database, $type, $identifier, $num_of_photos, $order)
|
|||
}
|
||||
break;
|
||||
case "user":
|
||||
$sql_photo_selector = "photo.users = '$identifier' and photo_version.master = 't' ";
|
||||
if ($order == 21) {
|
||||
$sql_photo_selector = "photo.identifier in (select * from get_random_photos($num_of_photos, $po_user[id], '{".$passwords."}', $identifier)) and photo_version.master = 't'";
|
||||
$order = 0;
|
||||
} else {
|
||||
$sql_photo_selector = "photo.users = '$identifier' and photo_version.master = 't' ";
|
||||
}
|
||||
break;
|
||||
case "album":
|
||||
$sql_photo_selector = "photo_version.identifier = album_content.version and photo.identifier = album_content.photo and album_content.album=".$identifier;
|
||||
|
|
|
@ -2,6 +2,39 @@
|
|||
-- v2.3X to XXXX patch (Unmerged stuff)
|
||||
----------------------------------------------------------
|
||||
|
||||
CREATE OR REPLACE FUNCTION get_random_photos(integer, integer, character varying[], integer) RETURNS SETOF integer AS '
|
||||
DECLARE num_rows alias for $1;
|
||||
viewer_id alias for $2;
|
||||
passwd_list alias for $3;
|
||||
user_id alias for $4;
|
||||
xmax INT;
|
||||
pick INT;
|
||||
matchid INT;
|
||||
safety INT = 0;
|
||||
rows INT = 0;
|
||||
BEGIN
|
||||
select last_value from photo_id_sequence into xmax;
|
||||
LOOP
|
||||
EXIT WHEN rows >= num_rows;
|
||||
|
||||
SELECT CEIL(xmax * RANDOM()) INTO pick;
|
||||
IF user_id > 0 THEN
|
||||
SELECT identifier FROM photo where identifier = pick and users = user_id and can_access_photo(identifier, viewer_id, passwd_list) INTO matchid;
|
||||
ELSE
|
||||
SELECT identifier FROM photo where identifier = pick and can_access_photo(identifier, viewer_id, passwd_list) INTO matchid;
|
||||
END IF;
|
||||
IF matchid IS NOT NULL THEN
|
||||
rows = rows + 1;
|
||||
RETURN NEXT matchid;
|
||||
END IF;
|
||||
|
||||
safety = safety + 1;
|
||||
EXIT WHEN safety > 10000;
|
||||
END LOOP;
|
||||
RETURN;
|
||||
END;
|
||||
' LANGUAGE plpgsql;
|
||||
|
||||
--------------------------------- DO NOT APPLY BELOW THIS LINE
|
||||
|
||||
alter table album add column parent_folder references folder(identifier);
|
||||
|
|
|
@ -105,6 +105,8 @@ if (($owner_id == 0) || ($owner_type < PO_USER_TYPE_CLIENT)) {
|
|||
display_clients($database, $po_user['id'], $auth_handle);
|
||||
}
|
||||
display_protected_photographers($database, $po_user['id']);
|
||||
|
||||
// site_display_top_photos($database, 'user', $po_user['id'], 20, FALSE);
|
||||
} else {
|
||||
if ($po_user['id']) {
|
||||
$client = pg_fetch_row(pg_query($database, "select identifier from client where users=$po_user[id] and client=$owner_id"));
|
||||
|
@ -147,7 +149,8 @@ if (($owner_id == 0) || ($owner_type < PO_USER_TYPE_CLIENT)) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
site_display_random_photos($database, 'user', $po_user['id'], 10, FALSE);
|
||||
}
|
||||
|
||||
site_footer($database);
|
||||
site_epilog($database);
|
||||
|
|
Loading…
Reference in New Issue