Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:34:04+00:00 2026-06-13T12:34:04+00:00

I’m currently hacking on an events site and have never had a problem optimizing

  • 0

I’m currently hacking on an events site and have never had a problem optimizing queries/scaling my db in the past as there was never that much data, but now there’s almost a million rows in the db and it’s taking ~15,000 m/s to render a feed of events, in particular the partial (within each _event.html.erb) that’s really slow is where all the users that youre currently following that are attending that event are displayed. I’ve looked up a lot of possibilities to improve performance including eager loading, indexing, memcache, etc…but was wondering how this can be rewritten to perform faster? Thank you!

_attending.html.erb

<% if user_signed_in? %>
        <% @rsvp = Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going') %>
        <% if @rsvp.count == 0 %>
            <%= eventcount(event) %> going.
        <% elsif @rsvp.count == 1 %>
            <% if eventcount(event) - 1 == 0 %>
                <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[0..0].each do |f| %>
                    <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %> is going.
                <% end %>
            <% else %>
              <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[0..0].each do |f| %>
                  <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %> and <%= eventcount(event) - 1 %> going.
              <% end %>
            <% end %>
        <% elsif @rsvp.count == 2 %>
            <% if eventcount(event) - 2 == 0 %>
                <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[0..0].each do |f| %>
                    <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %> and
                <% end %>
                <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[1..1].each do |f| %>
                    <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %> are going.
                <% end %>
            <% else %>
              <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[0..0].each do |f| %>
                  <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %>,
              <% end %>
              <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[1..1].each do |f| %>
                  <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %> and <%= eventcount(event) - 2 %> going.
              <% end %>
                <% end %>
        <% elsif @rsvp.count == 3 %>
            <% if eventcount(event) - 3 == 0 %>
                <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[0..0].each do |f| %>
                    <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %>,
                <% end %>
                <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[1..1].each do |f| %>
                    <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %>, and
                <% end %>
                <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[2..2].each do |f| %>
                    <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %> are going.
                <% end %>
            <% else %>
              <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[0..0].each do |f| %>
                  <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %>,
              <% end %>
              <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[1..1].each do |f| %>
                  <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %>,
              <% end %>
              <% Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going')[2..2].each do |f| %>
                  <%= link_to User.find(f.voter_id).name, User.find(f.voter_id).slug %> and <%= eventcount(event) - 3 %> are going.
              <% end %>
            <% end %>
            <% end %>
    <% else %>
        <%= eventcount(event) %> going.
    <% end %>

Schema for RSVP

create_table "rsvps", :force => true do |t|
  t.string    "status"
  t.integer   "event_id"
  t.integer   "voter_id"
  t.string    "voter_name"
  t.string    "voter_type"
  t.timestamp "created_at", :null => false
  t.timestamp "updated_at", :null => false
end

add_index "rsvps", ["voter_id", "voter_type", "event_id"], :name => "fk_one_rsvp_per_user_per_entity", :unique => true
add_index "rsvps", ["voter_id", "voter_type"], :name => "index_rsvps_on_voter_id_and_voter_type"

Schema for Relationship

create_table "relationships", :force => true do |t|
  t.integer   "follower_id"
  t.integer   "followed_id"
  t.timestamp "created_at",  :null => false
  t.timestamp "updated_at",  :null => false
end

add_index "relationships", ["followed_id"], :name => "index_relationships_on_followed_id"
add_index "relationships", ["follower_id"], :name => "index_relationships_on_follower_id"

Relevant part of User model

has_many :relationships, :foreign_key => "follower_id",
:dependent => :destroy

has_many :following, :through => :relationships, :source => :followed

has_many :reverse_relationships, :foreign_key => "followed_id",
       :class_name => "Relationship",
       :dependent => :destroy
has_many :followers, :through => :reverse_relationships, :source => :follower
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:34:05+00:00Added an answer on June 13, 2026 at 12:34 pm

    If the large db is the RSVP:

    You do a very large call to the db in your partial, try to reduce the n call Rsvp.where(:voter_id => current_user.following, :event_id => event.id, :status => 'going') only one time, and then working on it in the different cases. This can help a little in performance (every time you call a .where in large db is a complex process if you have a large db). Re-use the variable @rsvp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I am currently running into a problem where an element is coming back from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.