Skip to content
Snippets Groups Projects
Unverified Commit 90a8420f authored by Sébastien Gaya's avatar Sébastien Gaya Committed by GitHub
Browse files

Optimization backlinks (#1833)

* optimization backlink

* fix

* fix
parent 0f1f3de6
No related branches found
No related tags found
No related merge requests found
......@@ -18,8 +18,16 @@ class Communication::Block::Template::Organization < Communication::Block::Templ
def organizations
@organizations ||= elements.collect(&:organization).compact.uniq
end
def organization_ids
@organization_ids ||= @elements.collect(&:organization_id).compact.uniq
end
def children
organizations
end
def children_ids
organization_ids
end
end
......@@ -9,6 +9,10 @@ class Communication::Block::Template::Organization::Element < Communication::Blo
id_component.organization
end
def organization_id
id_component.data
end
def best_name
organization ? organization.name : name
end
......
......@@ -18,8 +18,16 @@ class Communication::Block::Template::Person < Communication::Block::Template::B
def people
@people ||= elements.collect(&:person).compact.uniq
end
def person_ids
@person_ids ||= @elements.collect(&:person_id).compact.uniq
end
def children
people
end
def children_ids
person_ids
end
end
......@@ -6,4 +6,8 @@ class Communication::Block::Template::Person::Element < Communication::Block::Te
def person
id_component.person
end
def person_id
id_component.data
end
end
......@@ -3,7 +3,7 @@ module Backlinkable
def backlinks_pages(website)
backlinks(
Communication::Website::Page,
"Communication::Website::Page",
website
)
.reject { |page| page.is_special_page? }
......@@ -11,14 +11,14 @@ module Backlinkable
def backlinks_posts(website)
backlinks(
Communication::Website::Post,
"Communication::Website::Post",
website
)
end
def backlinks_agenda_events(website)
backlinks(
Communication::Website::Agenda::Event,
"Communication::Website::Agenda::Event",
website
)
end
......@@ -26,15 +26,29 @@ module Backlinkable
protected
def backlinks(kind, website)
backlinks_blocks(website).published.map { |block|
block.about if backlink_in_block?(block, kind)
backlinks_object_ids = published_backlinks_blocks(website).map { |block|
block.about_id if backlink_in_block?(block, kind, website)
}.compact
kind.safe_constantize.published.where(communication_website_id: website.id, id: backlinks_object_ids)
end
def backlink_in_block?(block, kind)
block.about.is_a?(kind) && # Correct kind
self.in?(block.template.children) && # Mentioning self
block.about.published? # About published
def backlink_in_block?(block, kind, website)
block.about_type == kind && # Correct kind
block.about_id.in?(published_backlinks_object_ids(website, kind)) && # About published
self.id.in?(block.template.children_ids) # Mentioning self
end
def published_backlinks_object_ids(website, kind)
# Memoize to avoid multiple queries for the same website and kind
@published_backlinks_object_ids ||= {}
@published_backlinks_object_ids[website.id] ||= {}
@published_backlinks_object_ids[website.id][kind] ||= kind.safe_constantize.published.where(communication_website_id: website.id).pluck(:id)
end
def published_backlinks_blocks(website)
# Memoize to avoid multiple queries for the same website
@published_backlinks_blocks ||= {}
@published_backlinks_blocks[website.id] ||= backlinks_blocks(website).published
end
def backlinks_blocks(website)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment