Skip to content
This repository
Browse code

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
@@ -224,20 +224,20 @@ feed_data(FeedURL, MaxEnclosures) ->
224 224
225 225 get_directory() ->
226 226 {ok, _, Rows} =
227   - ?Q("SELECT \"user\", \"title\", \"image\", \"slug\", \"feed_title\" FROM directory", []),
  227 + ?Q("SELECT \"user\", \"title\", \"image\", \"slug\", \"feed_title\", \"lang\", \"types\" FROM directory", []),
228 228 group_directory_feeds(Rows).
229 229
230 230 group_directory_feeds([]) ->
231 231 [];
232   -group_directory_feeds([{User1, Title1, Image1, _, _} | _] = Directory) ->
  232 +group_directory_feeds([{User1, Title1, Image1, _, _, _, _} | _] = Directory) ->
233 233 {Directory1, Directory2} =
234 234 lists:splitwith(
235   - fun({User2, _, _, _, _}) ->
  235 + fun({User2, _, _, _, _, _, _}) ->
236 236 User1 == User2
237 237 end, Directory),
238 238 [{User1, Title1, Image1,
239   - [{Slug, FeedTitle}
240   - || {_, _, _, Slug, FeedTitle} <- Directory1]
  239 + [{Slug, FeedTitle, Lang, Types}
  240 + || {_, _, _, Slug, FeedTitle, Lang, Types} <- Directory1]
241 241 } | group_directory_feeds(Directory2)].
242 242
243 243
8 apps/ui/src/ui_template.erl
@@ -1079,10 +1079,12 @@ render_directory_item({User, Title, Image, Feeds}) ->
1079 1079 {a, [{href, ui_link:link_user(User)}], Title}}
1080 1080 },
1081 1081 {ul, [{class, "feeds"}],
1082   - [{li,
  1082 + [{li, [{'xml:lang', Lang},
  1083 + {'data-types', tl(lists:concat([[$,, Type]
  1084 + || Type <- Types]))}],
1083 1085 {a, [{href, ui_link:link_user_feed(User, Slug)}],
1084 1086 FeedTitle}
1085   - } || {Slug, FeedTitle} <- Feeds]
  1087 + } || {Slug, FeedTitle, Lang, Types} <- Feeds]
1086 1088 }
1087 1089 ]}
1088 1090 ]}.
@@ -1128,7 +1130,7 @@ export_directory_opml() ->
1128 1130 {htmlUrl, <<(ui_link:base())/binary, (ui_link:link_user_feed(User, Slug))/binary>>},
1129 1131 {xmlUrl, <<(ui_link:base())/binary, (ui_link:link_user_feed_xml(User, Slug))/binary>>}
1130 1132 ], []}
1131   - || {Slug, FeedTitle} <- Feeds
  1133 + || {Slug, FeedTitle, _Lang, _Types} <- Feeds
1132 1134 ]}
1133 1135 || {User, Title, _Image, Feeds} <- Directory
1134 1136 ]}
8 pg_meta.sql
@@ -96,9 +96,15 @@ CREATE OR REPLACE VIEW directory AS
96 96 COALESCE(users.title, users.name) As title,
97 97 users.image,
98 98 user_feeds.slug,
99   - COALESCE(user_feeds.title, feeds.title) AS feed_title
  99 + COALESCE(user_feeds.title, feeds.title) AS feed_title,
  100 + feeds.lang,
  101 + feed_types.types
100 102 FROM users
101 103 JOIN user_feeds ON (users.name=user_feeds."user")
102 104 JOIN feeds ON (user_feeds.feed=feeds.url)
  105 + JOIN (SELECT "feed", array_agg("type") AS types
  106 + FROM feed_types
  107 + GROUP BY "feed"
  108 + ) AS feed_types ON (user_feeds.feed=feed_types.feed)
103 109 WHERE user_feeds."public"=true
104 110 ORDER BY users.name ASC, user_feeds.slug ASC;
53 pg_var.sql
@@ -35,6 +35,59 @@ CREATE TABLE enclosures ("feed" TEXT NOT NULL,
35 35 ON DELETE CASCADE);
36 36 CREATE INDEX enclosures_url ON enclosures ("url");
37 37
  38 +-- Materialized distinct content types per feed
  39 +CREATE TABLE feed_types (
  40 + "feed" TEXT NOT NULL,
  41 + "type" TEXT,
  42 + PRIMARY KEY ("feed", "type")
  43 +);
  44 +CREATE OR REPLACE FUNCTION update_feed_type(
  45 + "f_feed" TEXT,
  46 + "f_type" TEXT
  47 +) RETURNS void AS $$
  48 + BEGIN
  49 + PERFORM TRUE
  50 + FROM enclosures
  51 + WHERE "feed"=f_feed AND "type"=f_type;
  52 +
  53 + IF NOT FOUND THEN
  54 + DELETE FROM enclosures
  55 + WHERE "feed"=f_feed AND "type"=f_type;
  56 + ELSE
  57 + BEGIN
  58 + INSERT INTO feed_types ("feed", "type")
  59 + VALUES (f_feed, f_type);
  60 + EXCEPTION
  61 + WHEN integrity_constraint_violation
  62 + THEN -- ignore
  63 + END;
  64 + END IF;
  65 + END;
  66 +$$ LANGUAGE plpgsql;
  67 +
  68 +CREATE OR REPLACE FUNCTION enclosures_update_feed_type(
  69 +) RETURNS trigger AS $$
  70 + BEGIN
  71 + PERFORM update_feed_type(NEW.feed, NEW.type);
  72 + RETURN NEW;
  73 + END;
  74 +$$ LANGUAGE plpgsql;
  75 +CREATE TRIGGER enclosures_update_feed_type
  76 + AFTER INSERT OR UPDATE ON enclosures
  77 + FOR EACH ROW
  78 + EXECUTE PROCEDURE enclosures_update_feed_type();
  79 +
  80 +CREATE OR REPLACE FUNCTION enclosures_update_feed_type_delete(
  81 +) RETURNS trigger AS $$
  82 + BEGIN
  83 + PERFORM update_feed_type(OLD.feed, OLD.type);
  84 + RETURN OLD;
  85 + END;
  86 +$$ LANGUAGE plpgsql;
  87 +CREATE TRIGGER enclosures_update_feed_type_delete
  88 + AFTER INSERT OR UPDATE ON enclosures
  89 + FOR EACH ROW
  90 + EXECUTE PROCEDURE enclosures_update_feed_type_delete();
38 91
39 92
40 93 CREATE INDEX enclosure_torrents_info_hash

0 comments on commit 0e96a24

Please sign in to comment.
Something went wrong with that request. Please try again.