Moved filter of nodes of type blog to the node storage layer.

This is more efficient because the result set from the query will be smaller and it will be easier to implement the pagination
This commit is contained in:
Dario Bösch
2015-05-21 14:06:08 +02:00
parent 6a782e412d
commit 4dd980963a
5 changed files with 51 additions and 44 deletions
+2 -2
View File
@@ -212,10 +212,10 @@ feature -- Access: Node
Result := node_storage.nodes Result := node_storage.nodes
end end
nodes_order_created_desc: LIST[CMS_NODE] blogs_order_created_desc: LIST[CMS_NODE]
-- List of nodes ordered by creation date (descending) -- List of nodes ordered by creation date (descending)
do do
Result := node_storage.nodes_order_created_desc Result := node_storage.blogs
end end
recent_nodes (a_offset, a_rows: INTEGER): LIST [CMS_NODE] recent_nodes (a_offset, a_rows: INTEGER): LIST [CMS_NODE]
+12 -5
View File
@@ -16,6 +16,15 @@ inherit
create create
make make
feature -- Settings
entries_per_page : INTEGER
-- The numbers of posts that are shown on one page. If there are more post a pagination is generated
do
-- For test reasons this is 2, so we don't have to create a lot of blog entries.
-- TODO: Set to bigger constant or load from global configuration file.
Result := 2
end
feature -- HTTP Methods feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE) do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor> -- <Precursor>
@@ -35,8 +44,8 @@ feature -- HTTP Methods
-- NOTE: for development purposes we have the following hardcode output. -- NOTE: for development purposes we have the following hardcode output.
create s.make_from_string ("<h2>Blog entries:</h2>") create s.make_from_string ("<h2>Blog</h2>")
if attached node_api.nodes_order_created_desc as lst then if attached node_api.blogs_order_created_desc as lst then
-- Filter out blog entries from all nodes -- Filter out blog entries from all nodes
--if n.content_type.is_equal ("blog") then --if n.content_type.is_equal ("blog") then
s.append ("<ul class=%"cms-blog-nodes%">%N") s.append ("<ul class=%"cms-blog-nodes%">%N")
@@ -44,7 +53,6 @@ feature -- HTTP Methods
lst as ic lst as ic
loop loop
n := ic.item n := ic.item
if n.content_type.is_equal ("blog") then
lnk := node_api.node_link (n) lnk := node_api.node_link (n)
s.append ("<li class=%"cms_type_"+ n.content_type +"%">") s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
@@ -73,13 +81,12 @@ feature -- HTTP Methods
s.append (l_page.formats.default_format.formatted_output (l_summary)) s.append (l_page.formats.default_format.formatted_output (l_summary))
end end
s.append ("<br />") s.append ("<br />")
s.append (l_page.link ("More...", lnk.location, Void)) s.append (l_page.link ("See more...", lnk.location, Void))
s.append ("</p>") s.append ("</p>")
end end
s.append ("</li>%N") s.append ("</li>%N")
end end
end
s.append ("</ul>%N") s.append ("</ul>%N")
--end --end
end end
@@ -70,7 +70,7 @@ feature -- Access
deferred deferred
end end
nodes_order_created_desc: LIST [CMS_NODE] blogs: LIST [CMS_NODE]
-- List of nodes ordered by creation date (descending). -- List of nodes ordered by creation date (descending).
deferred deferred
end end
@@ -41,7 +41,7 @@ feature -- Access: node
create {ARRAYED_LIST [CMS_NODE]} Result.make (0) create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end end
nodes_order_created_desc: LIST[CMS_NODE] blogs: LIST[CMS_NODE]
-- List of nodes ordered descending by creation date -- List of nodes ordered descending by creation date
do do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0) create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
@@ -33,7 +33,7 @@ feature -- Access
end end
end end
nodes_order_created_desc: LIST [CMS_NODE] blogs: LIST [CMS_NODE]
-- List of nodes ordered by creation date (descending). -- List of nodes ordered by creation date (descending).
do do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0) create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
@@ -42,7 +42,7 @@ feature -- Access
write_information_log (generator + ".nodes") write_information_log (generator + ".nodes")
from from
sql_query (sql_select_nodes_order_created_desc, Void) sql_query (sql_select_blogs_order_created_desc, Void)
sql_start sql_start
until until
sql_after sql_after
@@ -254,8 +254,8 @@ feature {NONE} -- Queries
-- SQL Query to retrieve all nodes. -- SQL Query to retrieve all nodes.
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
sql_select_nodes_order_created_desc: STRING = "SELECT * FROM Nodes WHERE status != -1 ORDER BY created DESC;" sql_select_blogs_order_created_desc: STRING = "SELECT * FROM Nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC;"
-- SQL Query to retrieve all nodes order by descending creation date. -- SQL Query to retrieve all nodes that are from the type "blog" ordered by descending creation date.
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM Nodes WHERE nid =:nid ORDER BY revision DESC, publish DESC LIMIT 1;" sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM Nodes WHERE nid =:nid ORDER BY revision DESC, publish DESC LIMIT 1;"