-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance for additional content boxes and tags index (#1750)
* Improve performance for additional content boxes and tags index * Modify followed_articles endpoint with new classic article api
- Loading branch information
1 parent
dd63720
commit 2d97a5d
Showing
18 changed files
with
153 additions
and
118 deletions.
There are no files selected for viewing
52 changes: 35 additions & 17 deletions
52
app/assets/javascripts/initializers/initializeAdditionalContentBoxes.js
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 |
---|---|---|
@@ -1,22 +1,40 @@ | ||
function initializeAdditionalContentBoxes() { | ||
var el = document.getElementById("additional-content-area"); | ||
var el = document.getElementById('additional-content-area'); | ||
if (el) { | ||
var d = new Date(); | ||
var signature = d.getTime().toString().substring(0, 5); | ||
window.fetch('/additional_content_boxes?article_id='+el.dataset.articleId+'&signature='+signature, { | ||
var signature = d | ||
.getTime() | ||
.toString() | ||
.substring(0, 5); | ||
var user = userData(); | ||
var stateParam = 'include_sponsors'; | ||
if (!user.display_sponsors) { | ||
stateParam = 'do_not_include_sponsors'; | ||
} | ||
window | ||
.fetch( | ||
'/additional_content_boxes?article_id=' + | ||
el.dataset.articleId + | ||
'&signature=' + | ||
signature + | ||
'&state=' + | ||
stateParam, | ||
{ | ||
method: 'GET', | ||
credentials: 'same-origin' | ||
}).then(function (response) { | ||
if (response.status === 200) { | ||
response.text().then(function(html){ | ||
el.innerHTML = html; | ||
initializeReadingListIcons(); | ||
initializeAllFollowButts(); | ||
initializeSponsorshipVisibility(); | ||
}) | ||
} else { | ||
// there's currently no errorCb. | ||
} | ||
}); | ||
credentials: 'same-origin', | ||
}, | ||
) | ||
.then(function(response) { | ||
if (response.status === 200) { | ||
response.text().then(function(html) { | ||
el.innerHTML = html; | ||
initializeReadingListIcons(); | ||
initializeAllFollowButts(); | ||
initializeSponsorshipVisibility(); | ||
}); | ||
} else { | ||
// there's currently no errorCb. | ||
} | ||
}); | ||
} | ||
} | ||
} |
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
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
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
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 |
---|---|---|
@@ -1,43 +1,45 @@ | ||
<div id="sidebar-wrapper-left" class="sidebar-wrapper sidebar-wrapper-left"> | ||
<div class="sidebar-bg" id="sidebar-bg-left"></div> | ||
<div class="side-bar"> | ||
<% if @tag_model && @tag_model.short_summary.present? %> | ||
<div class="widget"> | ||
<header> | ||
<h4>#<%= @tag %> 👋</h4> | ||
</header> | ||
<div class="widget-body"> | ||
<%= @tag_model.short_summary.html_safe %> | ||
<% cache "tag-sidebar-#{@tag}-#{@tag_model&.updated_at}-#{@tag_model&.taggings_count}", expires_in: 5.hour do %> | ||
<div id="sidebar-wrapper-left" class="sidebar-wrapper sidebar-wrapper-left"> | ||
<div class="sidebar-bg" id="sidebar-bg-left"></div> | ||
<div class="side-bar"> | ||
<% if @tag_model && @tag_model.short_summary.present? %> | ||
<div class="widget"> | ||
<header> | ||
<h4>#<%= @tag %> 👋</h4> | ||
</header> | ||
<div class="widget-body"> | ||
<%= @tag_model.short_summary.html_safe %> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% if @tag_model && @tag_model.rules_html.present? %> | ||
<div class="widget"> | ||
<header> | ||
<h4>submission guidelines</h4> | ||
</header> | ||
<div class="widget-body"> | ||
<%= @tag_model.rules_html.html_safe %> | ||
<a class="cta cta-button" href="/new/<%= @tag %>" > | ||
WRITE A POST | ||
</a> | ||
<% end %> | ||
<% if @tag_model && @tag_model.rules_html.present? %> | ||
<div class="widget"> | ||
<header> | ||
<h4>submission guidelines</h4> | ||
</header> | ||
<div class="widget-body"> | ||
<%= @tag_model.rules_html.html_safe %> | ||
<a class="cta cta-button" href="/new/<%= @tag %>" > | ||
WRITE A POST | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% if @tag_model && @tag_model.wiki_body_html.present? %> | ||
<div class="widget"> | ||
<header> | ||
<h4>about #<%= @tag %></h4> | ||
</header> | ||
<div class="widget-body"> | ||
<%= @tag_model.wiki_body_html.html_safe %> | ||
<% end %> | ||
<% if @tag_model && @tag_model.wiki_body_html.present? %> | ||
<div class="widget"> | ||
<header> | ||
<h4>about #<%= @tag %></h4> | ||
</header> | ||
<div class="widget-body"> | ||
<%= @tag_model.wiki_body_html.html_safe %> | ||
</div> | ||
</div> | ||
<% end %> | ||
<div class="sidebar-data"> | ||
<div> | ||
<%= pluralize Article.cached_tagged_with(@tag).where(published: true).size, "Post" %> Published | ||
</div> | ||
</div> | ||
<% end %> | ||
<div class="sidebar-data"> | ||
<div> | ||
<%= pluralize Article.cached_tagged_with(@tag).where(published: true).size, "Post" %> Published | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddTimestampsToTags < ActiveRecord::Migration[5.1] | ||
def change | ||
add_column :tags, :created_at, :datetime | ||
add_column :tags, :updated_at, :datetime | ||
end | ||
end |
Oops, something went wrong.