Skip to content

Commit

Permalink
sql: get_guid_downloads()
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Jan 19, 2015
1 parent af08eb3 commit f4ca709
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pg_downloads.sql
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,27 @@ CREATE OR REPLACE FUNCTION get_enclosure_downloads(
LEFT JOIN scraped ON (enclosure_torrents.info_hash=scraped.info_hash)
LEFT JOIN downloaded_stats ON (enclosure_torrents.info_hash=downloaded_stats.info_hash);
$$ LANGUAGE SQL;

CREATE OR REPLACE FUNCTION get_guid_downloads(
TEXT
) RETURNS SETOF download AS $$
SELECT user_feeds."user", user_feeds."slug", user_feeds."feed",
enclosures.item, enclosures.url AS enclosure,
COALESCE(user_feeds.title, feeds.title) AS feed_title, user_feeds."public" AS feed_public,
torrents.info_hash, torrents.name, torrents.size, enclosures.type,
feed_items.title, feed_items.lang, feed_items.summary, feed_items.published, feed_items.homepage, feed_items.payment, feed_items.image,
COALESCE(scraped.seeders, 0) AS "seeders", COALESCE(scraped.leechers, 0) AS "leechers",
COALESCE(scraped.upspeed, 0) AS "upspeed", COALESCE(scraped.downspeed, 0) AS "downspeed",
COALESCE(downloaded_stats.downloaded, 0) AS "downloaded"
FROM (SELECT feed, item, url, type FROM enclosures
WHERE guid=$1
LIMIT 100) AS enclosures
JOIN enclosure_torrents USING (url)
JOIN torrents USING (info_hash)
JOIN feed_items ON (enclosures.feed=feed_items.feed AND enclosures.item=feed_items.id)
JOIN feeds ON (feed_items.feed=feeds.url)
JOIN user_feeds ON (feed_items.feed=user_feeds.feed)
LEFT JOIN scraped ON (enclosure_torrents.info_hash=scraped.info_hash)
LEFT JOIN downloaded_stats ON (enclosure_torrents.info_hash=downloaded_stats.info_hash)
WHERE LENGTH(enclosure_torrents.info_hash)=20;
$$ LANGUAGE SQL;

0 comments on commit f4ca709

Please sign in to comment.