Skip to content

Commit

Permalink
Add profile_updated_at and github_repos_updated_at to avoid extra fet… (
Browse files Browse the repository at this point in the history
#1754)

* Add profile_updated_at and github_repos_updated_at to avoid extra fetches

* Fix variant_number issue

* Fix test
  • Loading branch information
benhalpern committed Feb 7, 2019
1 parent 7d6c85a commit 71a419e
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 154 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/v0/github_repos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def index
def update_or_create
@client = create_octokit_client
@repo = GithubRepo.find_or_create(fetched_repo_params)
current_user.touch(:github_repos_updated_at)
if @repo.valid?
render json: { featured: @repo.featured }
else
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/github_repos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def create
authorize GithubRepo
@client = create_octokit_client
@repo = GithubRepo.find_or_create(fetched_repo_params)
current_user.touch(:github_repos_updated_at)
if @repo.valid?
redirect_to "/settings/integrations", notice: "GitHub repo added"
else
Expand All @@ -15,6 +16,7 @@ def create

def update
@repo = GithubRepo.find(params[:id])
current_user.touch(:github_repos_updated_at)
authorize @repo
if @repo.update(featured: false)
redirect_to "/settings/integrations", notice: "GitHub repo added"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def create
end
end

# GET /users/:id/edit
def update
@user = current_user
@tab = "organization"
Expand All @@ -27,6 +26,7 @@ def update
authorize @organization

if @organization.update(organization_params)
@organization.touch(:profile_updated_at)
redirect_to "/settings/organization", notice: "Your organization was successfully updated."
else
render template: "users/edit"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def redirect_if_show_view_param

def handle_article_show
@article_show = true
@variant_number = params[:variant_version] || rand(2)
@variant_number = params[:variant_version] || (user_signed_in? ? 0 : rand(2))
assign_user_and_org
@comments_to_show_count = @article.cached_tag_list_array.include?("discuss") ? 50 : 30
assign_second_and_third_user
Expand Down
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def update
end

follow_hiring_tag(@user)
@user.touch(:profile_updated_at)
redirect_to "/settings/#{@tab}", notice: notice
else
render :edit
Expand Down
6 changes: 0 additions & 6 deletions app/decorators/organization_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,4 @@ def assigned_color
text: "#ffffff"
}
end

def key_profile_attributes
"#{bg_color_hex}-#{text_color_hex}-#{path}-#{tag_line}-
#{email}-#{company_size}-#{location}-#{summary}-#{cta_processed_html}-
#{cta_button_url}-#{cta_button_text}-#{profile_image_url}-#{name}"
end
end
7 changes: 0 additions & 7 deletions app/decorators/user_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,4 @@ def assigned_color
]
colors[id % 10]
end

def key_profile_attributes
"#{bg_color_hex}-#{text_color_hex}-#{path}-#{tag_line}-
#{email}-#{email_public}-#{employer_name}-#{employment_title}-
#{employer_url}-#{location}-#{education}-#{summary}-
#{looking_for_work_publicly}-#{created_at}-#{profile_image_url}-#{name}"
end
end
1 change: 1 addition & 0 deletions app/models/github_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def self.update_to_latest
stargazers_count: fetched_repo.stargazers_count,
info_hash: fetched_repo.to_hash,
)
repo.user&.touch(:github_repos_updated_at)
rescue StandardError => e
repo.destroy if e.message.include?("404 - Not Found")
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/articles/_sticky_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</div>
<% end %>
</div>
<% if @variant_number.to_i == 1 && !user_signed_in? %>
<% if @variant_number.to_i == 1 %>
<% cache("html-variant-sidebar#{rand(20)}", :expires_in => 8.hours) do %>
<% @html_variant = HtmlVariant.find_for_test(@article.cached_tag_list_array) %>
<% if @html_variant %>
Expand All @@ -71,7 +71,7 @@
<% end %>
<% end %>
<% else %>
<% cache("article-sticky-nav-articles-#{@article.id}-#{@actor.last_article_at}", :expires_in => 36.hours) do %>
<% cache("article-sticky-nav-articles-#{@article.id}-#{@actor.last_article_at}", :expires_in => 48.hours) do %>
<% @sticky_collection = StickyArticleCollection.new(@article, @organization || @user) %>
<% @sticky_articles = @sticky_collection.suggested_stickies %>
<% @user_stickies = @sticky_collection.user_stickies %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/articles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
</div>
</div>

<% cache("sticky-sidebar-#{@article.id}-#{(@organization || @user).decorate.key_profile_attributes}-#{(@organization || @user).last_article_at}-#{user_signed_in?}-#{@variant_number}", :expires_in => 24.hours) do %>
<% cache("sticky-sidebar-#{@article.id}-#{(@organization || @user).profile_updated_at}-#{(@organization || @user).last_article_at}-#{@variant_number}", :expires_in => 50.hours) do %>
<%= render "articles/sticky_nav" %>
<% end %>
Expand Down
92 changes: 48 additions & 44 deletions app/views/users/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,61 @@
<div class="sidebar-bg" id="sidebar-bg-left"></div>
<div class="side-bar">
<div class="user-sidebar">
<% if @user.mostly_work_with.present? %>
<div class="widget">
<header>
<h4>skills/languages</h4>
</header>
<div class="widget-body">
<%= sanitized_sidebar @user.mostly_work_with %>
<% cache "user-profile-sidebar-profile-details-#{@user.profile_updated_at}", expires_in: 10.days do %>
<% if @user.mostly_work_with.present? %>
<div class="widget">
<header>
<h4>skills/languages</h4>
</header>
<div class="widget-body">
<%= sanitized_sidebar @user.mostly_work_with %>
</div>
</div>
</div>
<% end %>
<% if @user.currently_learning.present? %>
<div class="widget">
<header>
<h4>learning/trying</h4>
</header>
<div class="widget-body">
<%= sanitized_sidebar @user.currently_learning %>
<% end %>
<% if @user.currently_learning.present? %>
<div class="widget">
<header>
<h4>learning/trying</h4>
</header>
<div class="widget-body">
<%= sanitized_sidebar @user.currently_learning %>
</div>
</div>
</div>
<% end %>
<% if @user.currently_hacking_on.present? %>
<div class="widget">
<header>
<h4>projects and hacks</h4>
</header>
<div class="widget-body">
<%= sanitized_sidebar @user.currently_hacking_on %>
<% end %>
<% if @user.currently_hacking_on.present? %>
<div class="widget">
<header>
<h4>projects and hacks</h4>
</header>
<div class="widget-body">
<%= sanitized_sidebar @user.currently_hacking_on %>
</div>
</div>
</div>
<% end %>
<% if @user.available_for.present? %>
<div class="widget">
<header>
<h4>available for</h4>
</header>
<div class="widget-body">
<%= sanitized_sidebar @user.available_for %>
</div>
</div>
<% end %>
<% end %>
<% if @user.available_for.present? %>
<div class="widget">
<header>
<h4>available for</h4>
</header>
<div class="widget-body">
<%= sanitized_sidebar @user.available_for %>
<% cache "user-profile-sidebar-stats-#{@user.last_article_at}-#{@user.last_comment_at}-#{@user.last_followed_at}", expires_in: 10.days do %>
<div class="sidebar-data">
<div>
<%= pluralize @user.articles.where(published: true).size, "Post" %> Published
</div>
<div>
<%= pluralize @user.comments.where(deleted: false).size, "Comment" %> Written
</div>
<div>
<%= pluralize @user.decorate.cached_followed_tags.size, "Tag" %> Followed
</div>
</div>
<% end %>
<div class="sidebar-data">
<div>
<%= pluralize @user.articles.where(published: true).size, "Post" %> Published
</div>
<div>
<%= pluralize @user.comments.where(deleted: false).size, "Comment" %> Written
</div>
<div>
<%= pluralize @user.decorate.cached_followed_tags.size, "Tag" %> Followed
</div>
</div>
</div>
</div>
</div>

0 comments on commit 71a419e

Please sign in to comment.