Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sql, model, ui: directory with lang & feed_types

  • Loading branch information...
commit 0e96a24cd80afc83178c6539d7c5064d1625640c 1 parent b16d693
Astro authored
10 apps/model/src/model_feeds.erl
View
@@ -224,20 +224,20 @@ feed_data(FeedURL, MaxEnclosures) ->
get_directory() ->
{ok, _, Rows} =
- ?Q("SELECT \"user\", \"title\", \"image\", \"slug\", \"feed_title\" FROM directory", []),
+ ?Q("SELECT \"user\", \"title\", \"image\", \"slug\", \"feed_title\", \"lang\", \"types\" FROM directory", []),
group_directory_feeds(Rows).
group_directory_feeds([]) ->
[];
-group_directory_feeds([{User1, Title1, Image1, _, _} | _] = Directory) ->
+group_directory_feeds([{User1, Title1, Image1, _, _, _, _} | _] = Directory) ->
{Directory1, Directory2} =
lists:splitwith(
- fun({User2, _, _, _, _}) ->
+ fun({User2, _, _, _, _, _, _}) ->
User1 == User2
end, Directory),
[{User1, Title1, Image1,
- [{Slug, FeedTitle}
- || {_, _, _, Slug, FeedTitle} <- Directory1]
+ [{Slug, FeedTitle, Lang, Types}
+ || {_, _, _, Slug, FeedTitle, Lang, Types} <- Directory1]
} | group_directory_feeds(Directory2)].
8 apps/ui/src/ui_template.erl
View
@@ -1079,10 +1079,12 @@ render_directory_item({User, Title, Image, Feeds}) ->
{a, [{href, ui_link:link_user(User)}], Title}}
},
{ul, [{class, "feeds"}],
- [{li,
+ [{li, [{'xml:lang', Lang},
+ {'data-types', tl(lists:concat([[$,, Type]
+ || Type <- Types]))}],
{a, [{href, ui_link:link_user_feed(User, Slug)}],
FeedTitle}
- } || {Slug, FeedTitle} <- Feeds]
+ } || {Slug, FeedTitle, Lang, Types} <- Feeds]
}
]}
]}.
@@ -1128,7 +1130,7 @@ export_directory_opml() ->
{htmlUrl, <<(ui_link:base())/binary, (ui_link:link_user_feed(User, Slug))/binary>>},
{xmlUrl, <<(ui_link:base())/binary, (ui_link:link_user_feed_xml(User, Slug))/binary>>}
], []}
- || {Slug, FeedTitle} <- Feeds
+ || {Slug, FeedTitle, _Lang, _Types} <- Feeds
]}
|| {User, Title, _Image, Feeds} <- Directory
]}
8 pg_meta.sql
View
@@ -96,9 +96,15 @@ CREATE OR REPLACE VIEW directory AS
COALESCE(users.title, users.name) As title,
users.image,
user_feeds.slug,
- COALESCE(user_feeds.title, feeds.title) AS feed_title
+ COALESCE(user_feeds.title, feeds.title) AS feed_title,
+ feeds.lang,
+ feed_types.types
FROM users
JOIN user_feeds ON (users.name=user_feeds."user")
JOIN feeds ON (user_feeds.feed=feeds.url)
+ JOIN (SELECT "feed", array_agg("type") AS types
+ FROM feed_types
+ GROUP BY "feed"
+ ) AS feed_types ON (user_feeds.feed=feed_types.feed)
WHERE user_feeds."public"=true
ORDER BY users.name ASC, user_feeds.slug ASC;
53 pg_var.sql
View
@@ -35,6 +35,59 @@ CREATE TABLE enclosures ("feed" TEXT NOT NULL,
ON DELETE CASCADE);
CREATE INDEX enclosures_url ON enclosures ("url");
+-- Materialized distinct content types per feed
+CREATE TABLE feed_types (
+ "feed" TEXT NOT NULL,
+ "type" TEXT,
+ PRIMARY KEY ("feed", "type")
+);
+CREATE OR REPLACE FUNCTION update_feed_type(
+ "f_feed" TEXT,
+ "f_type" TEXT
+) RETURNS void AS $$
+ BEGIN
+ PERFORM TRUE
+ FROM enclosures
+ WHERE "feed"=f_feed AND "type"=f_type;
+
+ IF NOT FOUND THEN
+ DELETE FROM enclosures
+ WHERE "feed"=f_feed AND "type"=f_type;
+ ELSE
+ BEGIN
+ INSERT INTO feed_types ("feed", "type")
+ VALUES (f_feed, f_type);
+ EXCEPTION
+ WHEN integrity_constraint_violation
+ THEN -- ignore
+ END;
+ END IF;
+ END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION enclosures_update_feed_type(
+) RETURNS trigger AS $$
+ BEGIN
+ PERFORM update_feed_type(NEW.feed, NEW.type);
+ RETURN NEW;
+ END;
+$$ LANGUAGE plpgsql;
+CREATE TRIGGER enclosures_update_feed_type
+ AFTER INSERT OR UPDATE ON enclosures
+ FOR EACH ROW
+ EXECUTE PROCEDURE enclosures_update_feed_type();
+
+CREATE OR REPLACE FUNCTION enclosures_update_feed_type_delete(
+) RETURNS trigger AS $$
+ BEGIN
+ PERFORM update_feed_type(OLD.feed, OLD.type);
+ RETURN OLD;
+ END;
+$$ LANGUAGE plpgsql;
+CREATE TRIGGER enclosures_update_feed_type_delete
+ AFTER INSERT OR UPDATE ON enclosures
+ FOR EACH ROW
+ EXECUTE PROCEDURE enclosures_update_feed_type_delete();
CREATE INDEX enclosure_torrents_info_hash
Please sign in to comment.
Something went wrong with that request. Please try again.