4 failures left in postgres
This commit is contained in:
parent
4d4d11b90b
commit
bf0eb3dac3
8 changed files with 46 additions and 24 deletions
|
|
@ -57,7 +57,7 @@ class CommentsController < ApplicationController
|
|||
def index
|
||||
@post = current_user.find_visible_post_by_id(params[:post_id])
|
||||
if @post
|
||||
@comments = @post.comments.includes(:author => :profile)
|
||||
@comments = @post.comments.includes(:author => :profile).order('created_at ASC')
|
||||
render :layout => false
|
||||
else
|
||||
raise ActiveRecord::RecordNotFound.new
|
||||
|
|
|
|||
|
|
@ -14,12 +14,23 @@ module Job
|
|||
socket_to_users(post, recipient_user_ids) if post.respond_to?(:socket_to_user)
|
||||
notify_mentioned_users(post)
|
||||
end
|
||||
|
||||
def self.create_visibilities(post, recipient_user_ids)
|
||||
contacts = Contact.where(:user_id => recipient_user_ids, :person_id => post.author_id)
|
||||
new_post_visibilities = contacts.map do |contact|
|
||||
PostVisibility.new(:contact_id => contact.id, :post_id => post.id)
|
||||
|
||||
if postgres?
|
||||
# Take the naive approach to inserting our new visibilities for now.
|
||||
contacts.each do |contact|
|
||||
PostVisibility.find_or_create_by_contact_id_and_post_id(contact.id, post.id)
|
||||
end
|
||||
else
|
||||
# Use a batch insert on mySQL.
|
||||
new_post_visibilities = contacts.map do |contact|
|
||||
PostVisibility.new(:contact_id => contact.id, :post_id => post.id)
|
||||
end
|
||||
PostVisibility.import(new_post_visibilities)
|
||||
end
|
||||
PostVisibility.import new_post_visibilities
|
||||
|
||||
end
|
||||
def self.socket_to_users(post, recipient_user_ids)
|
||||
recipient_user_ids.each do |id|
|
||||
|
|
|
|||
|
|
@ -67,18 +67,12 @@ class Person < ActiveRecord::Base
|
|||
|
||||
def self.search_query_string(query)
|
||||
query = query.downcase
|
||||
like_operator = postgres? ? "ILIKE" : "LIKE"
|
||||
|
||||
if postgres?
|
||||
where_clause = <<-SQL
|
||||
profiles.full_name ILIKE ? OR
|
||||
profiles.diaspora_handle ILIKE ?
|
||||
SQL
|
||||
else
|
||||
where_clause = <<-SQL
|
||||
profiles.full_name LIKE ? OR
|
||||
people.diaspora_handle LIKE ?
|
||||
SQL
|
||||
end
|
||||
where_clause = <<-SQL
|
||||
profiles.full_name #{like_operator} ? OR
|
||||
people.diaspora_handle #{like_operator} ?
|
||||
SQL
|
||||
|
||||
q_tokens = query.to_s.strip.gsub(/(\s|$|^)/) { "%#{$1}" }
|
||||
[where_clause, [q_tokens, q_tokens]]
|
||||
|
|
|
|||
|
|
@ -42,7 +42,16 @@ class Services::Facebook < Service
|
|||
su.attach_local_models
|
||||
su
|
||||
}
|
||||
ServiceUser.import(data, :on_duplicate_key_update => [:updated_at, :contact_id, :person_id, :request_id, :invitation_id, :photo_url, :name, :username])
|
||||
|
||||
|
||||
if postgres?
|
||||
# Take the naive approach to inserting our new visibilities for now.
|
||||
data.each do |su|
|
||||
su.save
|
||||
end
|
||||
else
|
||||
ServiceUser.import(data, :on_duplicate_key_update => [:updated_at, :contact_id, :person_id, :request_id, :invitation_id, :photo_url, :name, :username])
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@ SQL
|
|||
SQL
|
||||
|
||||
#There are some duplicate likes.
|
||||
keeper_likes = Like.group(:target_id, :author_id, :target_type).having('COUNT(*) > 1')
|
||||
keeper_likes.each do |like|
|
||||
l = Like.arel_table
|
||||
Like.where(:target_id => like.target_id, :author_id => like.author_id, :target_type => like.target_type).where(l[:id].not_eq(like.id)).delete_all
|
||||
if Like.count > 0
|
||||
keeper_likes = Like.group(:target_id, :author_id, :target_type).having('COUNT(*) > 1')
|
||||
keeper_likes.each do |like|
|
||||
l = Like.arel_table
|
||||
Like.where(:target_id => like.target_id, :author_id => like.author_id, :target_type => like.target_type).where(l[:id].not_eq(like.id)).delete_all
|
||||
end
|
||||
end
|
||||
add_index :likes, [:target_id, :author_id, :target_type], :unique => true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
class AddFullNameToProfile < ActiveRecord::Migration
|
||||
class Profile < ActiveRecord::Base; end
|
||||
def self.up
|
||||
add_column :profiles, :full_name, :string, :limit => 70
|
||||
|
||||
|
|
@ -8,7 +9,13 @@ class AddFullNameToProfile < ActiveRecord::Migration
|
|||
remove_index :profiles, [:first_name, :searchable]
|
||||
remove_index :profiles, [:last_name, :searchable]
|
||||
|
||||
execute("UPDATE profiles SET full_name=LOWER(CONCAT(first_name, ' ', last_name))")
|
||||
if Profile.count > 0
|
||||
if postgres?
|
||||
execute("UPDATE profiles SET full_name=LOWER(first_name || ' ' || last_name)")
|
||||
else
|
||||
execute("UPDATE profiles SET full_name=LOWER(CONCAT(first_name, ' ', last_name))")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ describe GettingStartedHelper do
|
|||
it 'returns true if the current user has filled out all 7 suggested fields (from getting started)' do
|
||||
profile = @current_user.person.profile
|
||||
profile.update_attributes!(
|
||||
{:first_name => "alice", :last_name => "smith", :image_url => "abcd.jpg", :birthday => Date.new,
|
||||
{:first_name => "alice", :last_name => "smith", :image_url => "abcd.jpg", :birthday => Time.now,
|
||||
:gender => "cow", :location => "san fran", :tag_string => "#sup", :bio => "holler" })
|
||||
has_completed_profile?.should be_true
|
||||
end
|
||||
|
|
@ -59,7 +59,7 @@ describe GettingStartedHelper do
|
|||
end
|
||||
|
||||
it 'returns false if the current_user has less than 2 contacts (inclusive)' do
|
||||
@current_user.contacts.delete_all
|
||||
@current_user.contacts.destroy_all
|
||||
has_few_contacts?.should be_false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -272,7 +272,6 @@ describe 'a user receives a post' do
|
|||
post_in_db.comments.should == []
|
||||
|
||||
receive_with_zord(bob, alice.person, @xml)
|
||||
|
||||
post_in_db.comments(true).first.author.should == remote_person
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue