-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize getting latest feed item in specific hub feed
- Loading branch information
1 parent
0b57e21
commit 6416b83
Showing
5 changed files
with
87 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
db/migrate/20241009105912_create_get_latest_feed_item_function.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class CreateGetLatestFeedItemFunction < ActiveRecord::Migration[5.1] | ||
def up | ||
execute <<-SQL | ||
CREATE FUNCTION get_latest_feed_item(feed_id_param INTEGER) | ||
RETURNS TABLE(id INTEGER, title VARCHAR, url VARCHAR, guid VARCHAR, authors VARCHAR, contributors VARCHAR, description VARCHAR, content VARCHAR, rights VARCHAR, date_published TIMESTAMP, last_updated TIMESTAMP, created_at TIMESTAMP, updated_at TIMESTAMP, image_url TEXT) AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
WITH relevant_feed_items AS ( | ||
SELECT feed_item_id | ||
FROM feed_items_feeds | ||
WHERE feed_id = feed_id_param | ||
) | ||
SELECT fi.* | ||
FROM feed_items fi | ||
JOIN relevant_feed_items rfi ON fi.id = rfi.feed_item_id | ||
ORDER BY fi.date_published DESC | ||
LIMIT 1; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
SQL | ||
end | ||
|
||
def down | ||
execute <<-SQL | ||
DROP FUNCTION IF EXISTS get_latest_feed_item(INTEGER); | ||
SQL | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters