Super small queries optimizations (#1586)
* Replace find_by().nil? with exists? find_by asks the DB and the ORM to load the entire object in memory, then it is discarded just know if it exists or not. Exists will just return true or false * Use present? in lieu of any? when it is proper A request for any? followed by each in a most likely full collection results in two SQL queries. present? preloads the objects, so it results in one single connection because the objects are already in memory.
This commit is contained in:
parent
de0dc2f2a8
commit
c989cbf301
3 changed files with 5 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<div id="sidebar-wrapper-right" class="sidebar-wrapper sidebar-wrapper-right">
|
||||
<div class="sidebar-bg" id="sidebar-bg-right"></div>
|
||||
<div class="side-bar sidebar-additional showing" id="sidebar-additional">
|
||||
<% if @organization.users.any? %>
|
||||
<% if @organization.users.present? %>
|
||||
<div class="widget">
|
||||
<div class="widget-suggested-follows-container">
|
||||
<header><h4>meet the team</h4></header>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<% if @user.identities.find_by(provider:'github').nil? %>
|
||||
<% unless @user.identities.exists?(provider:'github') %>
|
||||
<div class="field">
|
||||
<a href="/users/auth/github" class="big-button cta" data-no-instant>
|
||||
<img src="<%= asset_path('github-logo.svg') %>" /> CONNECT GITHUB ACCOUNT
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
<% end %>
|
||||
|
||||
|
||||
<% if @user.identities.find_by(provider:'twitter').nil? %>
|
||||
<% unless @user.identities.exists?(provider:'twitter') %>
|
||||
<div class="field">
|
||||
<a href="/users/auth/twitter?callback_url=<%= ApplicationConfig["APP_PROTOCOL"] %><%= ApplicationConfig["APP_DOMAIN"] %>/users/auth/twitter/callback" class="big-button cta" data-no-instant>
|
||||
<img src="<%= asset_path('twitter-logo.svg') %>" /> CONNECT TWITTER ACCOUNT
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jscolor/2.0.4/jscolor.min.js" async="async"></script>
|
||||
<% if @user.identities.find_by(provider:'github').nil? %>
|
||||
<% unless @user.identities.exists?(provider:'github') %>
|
||||
<div class="field">
|
||||
<a href="/users/auth/github" class="big-button cta" data-no-instant>
|
||||
<img src="<%= asset_path('github-logo.svg') %>" /> CONNECT GITHUB ACCOUNT
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @user.identities.find_by(provider:'twitter').nil? %>
|
||||
<% unless @user.identities.exists?(provider:'twitter') %>
|
||||
<div class="field">
|
||||
<a href="/users/auth/twitter?callback_url=<%= ApplicationConfig["APP_PROTOCOL"] %><%= ApplicationConfig["APP_DOMAIN"] %>/users/auth/twitter/callback" class="big-button cta" data-no-instant>
|
||||
<img src="<%= asset_path('twitter-logo.svg') %>" /> CONNECT TWITTER ACCOUNT
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue