counters for linked feeds, misc SQL optimizations

This commit is contained in:
Andrew Dolgov 2005-12-29 07:19:27 +01:00
parent 587b0b084d
commit db42b934a1
2 changed files with 65 additions and 32 deletions

View File

@ -228,7 +228,7 @@
} }
} }
function getFeedCounter($link, $id) { /* function getFeedCounter($link, $id) {
$result = db_query($link, "SELECT $result = db_query($link, "SELECT
count(id) as count,last_error count(id) as count,last_error
@ -241,7 +241,7 @@
$last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error")); $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error"));
print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>"; print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>";
} } */
function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) { function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
@ -253,13 +253,14 @@
$old_counters = $_SESSION["fctr_last_value"]; $old_counters = $_SESSION["fctr_last_value"];
$result = db_query($link, "SELECT id,last_error, $result = db_query($link, "SELECT id,last_error,parent_feed,
(SELECT count(id) (SELECT count(id)
FROM ttrss_entries,ttrss_user_entries FROM ttrss_entries,ttrss_user_entries
WHERE feed_id = ttrss_feeds.id AND WHERE feed_id = ttrss_feeds.id AND
ttrss_user_entries.ref_id = ttrss_entries.id ttrss_user_entries.ref_id = ttrss_entries.id
AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]); FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . "
AND parent_feed IS NULL");
$fctrs_modified = false; $fctrs_modified = false;
@ -267,10 +268,22 @@
$id = $line["id"]; $id = $line["id"];
$count = $line["count"]; $count = $line["count"];
$last_error = htmlspecialchars($line["last_error"]); $last_error = htmlspecialchars($line["last_error"]);
$has_img = is_file(ICONS_DIR . "/$id.ico"); $has_img = is_file(ICONS_DIR . "/$id.ico");
$tmp_result = db_query($link,
"SELECT id,COUNT(unread) AS unread
FROM ttrss_feeds LEFT JOIN ttrss_user_entries
ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
WHERE parent_feed = '$id' AND unread = true GROUP BY ttrss_feeds.id");
if (db_num_rows($tmp_result) > 0) {
while ($l = db_fetch_assoc($tmp_result)) {
$count += $l["unread"];
}
}
if (!$smart_mode || $old_counters[$id] != $count) { if (!$smart_mode || $old_counters[$id] != $count) {
$old_counters[$id] = $count; $old_counters[$id] = $count;
$fctrs_modified = true; $fctrs_modified = true;
@ -413,24 +426,24 @@
$order_by_qpart = "title"; $order_by_qpart = "title";
} }
$result = db_query($link, "SELECT *, $result = db_query($link, "SELECT ttrss_feeds.*,
(SELECT count(id) FROM ttrss_entries,ttrss_user_entries (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
WHERE feed_id = ttrss_feeds.id AND WHERE feed_id = ttrss_feeds.id AND
ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.ref_id = ttrss_entries.id AND
owner_uid = '$owner_uid') AS total, owner_uid = '$owner_uid') AS total,
(SELECT count(id) FROM ttrss_entries,ttrss_user_entries (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
WHERE feed_id = ttrss_feeds.id AND unread = true WHERE feed_id = ttrss_feeds.id AND unread = true
AND ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.ref_id = ttrss_entries.id
AND owner_uid = '$owner_uid') as unread, AND owner_uid = '$owner_uid') as unread,
(SELECT title FROM ttrss_feed_categories
WHERE id = cat_id) AS category,
cat_id,last_error, cat_id,last_error,
(SELECT collapsed FROM ttrss_feed_categories ttrss_feed_categories.title AS category,
WHERE id = cat_id) AS collapsed ttrss_feed_categories.collapsed
FROM ttrss_feeds WHERE FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
owner_uid = '$owner_uid' AND parent_feed IS NULL ON (ttrss_feed_categories.id = cat_id)
ORDER BY $order_by_qpart"); WHERE
ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
ORDER BY $order_by_qpart");
$actid = $_GET["actid"]; $actid = $_GET["actid"];
/* real feeds */ /* real feeds */
@ -451,6 +464,19 @@
$total = $line["total"]; $total = $line["total"];
$unread = $line["unread"]; $unread = $line["unread"];
$tmp_result = db_query($link,
"SELECT id,COUNT(unread) AS unread
FROM ttrss_feeds LEFT JOIN ttrss_user_entries
ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
WHERE parent_feed = '$feed_id' AND unread = true
GROUP BY ttrss_feeds.id");
if (db_num_rows($tmp_result) > 0) {
while ($l = db_fetch_assoc($tmp_result)) {
$unread += $l["unread"];
}
}
$cat_id = $line["cat_id"]; $cat_id = $line["cat_id"];
$tmp_category = $line["category"]; $tmp_category = $line["category"];
@ -1874,17 +1900,24 @@
} }
$result = db_query($link, "SELECT $result = db_query($link, "SELECT
id,title,feed_url,substring(last_updated,1,16) as last_updated, F1.id,
update_interval,purge_interval,cat_id, F1.title,
parent_feed AS parent_feed_id, F1.feed_url,
(SELECT title FROM ttrss_feed_categories substring(F1.last_updated,1,16) AS last_updated,
WHERE id = cat_id) AS category, F1.parent_feed,
(SELECT title FROM ttrss_feeds F1.update_interval,
WHERE id = parent_feed_id) AS parent_title F1.purge_interval,
F1.cat_id,
F2.title AS parent_title,
C1.title AS category
FROM FROM
ttrss_feeds ttrss_feeds AS F1
LEFT JOIN ttrss_feeds AS F2
ON (F1.parent_feed = F2.id)
LEFT JOIN ttrss_feed_categories AS C1
ON (F1.cat_id = C1.id)
WHERE WHERE
$search_qpart owner_uid = '".$_SESSION["uid"]."' $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
ORDER by category,$feeds_sort,title"); ORDER by category,$feeds_sort,title");
if (db_num_rows($result) != 0) { if (db_num_rows($result) != 0) {

View File

@ -245,12 +245,12 @@
$filters = array(); $filters = array();
$result = db_query($link, "SELECT reg_exp, $result = db_query($link, "SELECT reg_exp,
(SELECT name FROM ttrss_filter_types ttrss_filter_types.name AS name,
WHERE id = filter_type) as name, ttrss_filter_actions.name AS action
(SELECT name FROM ttrss_filter_actions FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE
WHERE id = action_id) as action owner_uid = $owner_uid AND
FROM ttrss_filters WHERE ttrss_filter_types.id = filter_type AND
owner_uid = $owner_uid AND ttrss_filter_actions.id = action_id AND
(feed_id IS NULL OR feed_id = '$feed')"); (feed_id IS NULL OR feed_id = '$feed')");
while ($line = db_fetch_assoc($result)) { while ($line = db_fetch_assoc($result)) {