Permalink
Browse files

Merge branch 'dev' of github.com:umamao/umamao into only-question-new…

…s-items
  • Loading branch information...
2 parents 3943bca + bc4fba0 commit ce59a0f3673fb258e9fd5a04e3543b4350fc9e58 @andlima andlima committed Nov 25, 2011
View
@@ -15,6 +15,7 @@ log/
tmp/**/*
dump
*.swp
+*.swo
*~
vendor/cache
public/stylesheets/compiled
@@ -80,6 +80,7 @@ def signup_with_provider
end
if user = User.create_with_provider(auth_hash)
+ current_group.add_member(user)
invitation_type = session['invitation_type']
ref = session['invitation_id'] if invitation_type == "UrlInvitation"
slug = session["invitation_id"] if invitation_type == "GroupInvitation"
View
@@ -169,12 +169,12 @@ def add_member(user, role = 'user')
end
def users(conditions = {})
- User.all(conditions.merge("membership_list.#{self.id}.reputation" => {:$exists => true}))
+ User.all(conditions)
end
alias_method :members, :users
def paginate_users(conditions = {})
- User.paginate(conditions.merge("membership_list.#{self.id}.reputation" => {:$exists => true}))
+ User.paginate(conditions)
end
def pending?
@@ -51,7 +51,7 @@ class SearchResult
:unless => :summary_present?,
:if => [:response_body_present?, :response_body_text?]
- after_create :create_news_update
+ after_create :create_news_update, :increment_user_topic_answers_count
after_create :notify_watchers, :unless => :has_answer?
after_create Proc.new { |sr| sr.question.search_result_added! }
@@ -63,6 +63,10 @@ class SearchResult
validates_presence_of :url
validates_uniqueness_of(:url, :scope => :question_id)
+ def increment_user_topic_answers_count
+ UserTopicInfo.answer_added!(self)
+ end
+
def topics
question.topics
end
View
@@ -167,8 +167,8 @@ def update_related_topics!
self.find_related_topics
# if an error happens during set, set will return a Hash with it
- errors_ids = self.set(:related_topic_ids, self.related_topics_id)
- errors_count = self.set(:related_topics_count, self.related_topics_count)
+ errors_ids = self.set(:related_topic_ids => self.related_topics_id)
+ errors_count = self.set(:related_topics_count => self.related_topics_count)
# only return true if both fields could be updated properly
!(errors_ids.is_a?(Hash) || errors_count.is_a?(Hash))
@@ -27,21 +27,22 @@ def followed?
def follow
self.unignore
- self.followed_at ||= Time.now
+ self.followed_at ||= Time.zone.now
end
def follow!
- self.follow
- self.save!
+ self.unignore!
+ self.set(:followed_at => Time.zone.now) unless self.followed?
+ self.reload
end
def unfollow
self.followed_at = nil
end
def unfollow!
- self.unfollow
- self.save!
+ self.set(:followed_at => nil)
+ self.reload
end
def ignored?
@@ -50,21 +51,22 @@ def ignored?
def ignore
self.unfollow
- self.ignored_at ||= Time.now
+ self.ignored_at ||= Time.zone.now
end
def ignore!
- self.ignore
- self.save!
+ self.unfollow!
+ self.set(:ignored_at => Time.zone.now) unless self.ignored?
+ self.reload
end
def unignore
self.ignored_at = nil
end
def unignore!
- self.unignore
- self.save!
+ self.set(:ignored_at => nil)
+ self.reload
end
def self.question_added!(question)
@@ -79,11 +81,11 @@ def self.question_removed!(question)
end
end
- def self.answer_added!(answer)
- return if answer.question.nil?
+ def self.answer_added!(answer_or_search_result)
+ return if answer_or_search_result.question.nil?
- answer.question.topics.each do |topic|
- update_answer_topic(answer.user, topic)
+ answer_or_search_result.question.topics.each do |topic|
+ update_answer_topic(answer_or_search_result.user, topic)
end
end
@@ -94,10 +96,7 @@ def self.answer_removed!(answer)
end
def self.reset_answers_count!
- self.find_each do |user_topic|
- user_topic.answers_count = 0
- user_topic.save
- end
+ self.set({}, :answers_count => 0)
end
def self.vote_added!(answer, vote)
@@ -116,15 +115,12 @@ def self.update_vote_balance!(answer)
return if answer.question.nil?
answer.question.topics.each do |topic|
- self.update_votes_balance(answer.user, topic, answer.votes_average)
+ self.increment_votes_balance(answer.user, topic, answer.votes_average)
end
end
def self.reset_votes_balance!
- self.find_each do |user_topic|
- user_topic.votes_balance = 0
- user_topic.save
- end
+ self.set({}, :votes_balance => 0)
end
def self.question_classified!(question, topic)
@@ -169,8 +165,7 @@ def self.update_question_topic(user, topic, increment=1)
user_topic = UserTopicInfo.first(:topic_id => topic.id,
:user_id => user.id)
if user_topic
- user_topic.questions_count += increment
- user_topic.save
+ user_topic.increment(:questions_count => increment)
else
increment = [increment, 0].max
UserTopicInfo.create(:topic_id => topic.id, :user_id => user.id,
@@ -182,8 +177,7 @@ def self.update_answer_topic(user, topic, increment=1)
user_topic = UserTopicInfo.first(:topic_id => topic.id,
:user_id => user.id)
if user_topic
- user_topic.answers_count += increment
- user_topic.save
+ user_topic.increment(:answers_count => increment)
else
increment = [increment, 0].max
UserTopicInfo.create(:topic_id => topic.id, :user_id => user.id,
@@ -196,8 +190,7 @@ def self.increment_votes_balance(user, topic, increment)
:user_id => user.id)
if user_topic
- user_topic.votes_balance += increment
- user_topic.save
+ user_topic.increment(:votes_balance => increment)
else
UserTopicInfo.create(
:topic_id => topic.id, :user_id => user.id, :votes_balance => increment)
@@ -209,8 +202,8 @@ def self.update_votes_balance(user, topic, vote)
:user_id => user.id)
if user_topic
- user_topic.votes_balance = vote
- user_topic.save
+ user_topic.set(:votes_balance => vote)
+ user_topic.reload
else
UserTopicInfo.create(
:topic_id => topic.id, :user_id => user.id, :votes_balance => vote)
@@ -345,7 +345,7 @@ form#new_search_result
padding-top: 1em
.submit_button
float: none
- text-align: left
+ text-align: right
width: 100%
input#search_result_url.link_only_answer_form
float: none
@@ -55,9 +55,9 @@ namespace :data do
UserTopicInfo.reset_votes_balance!
UserTopicInfo.reset_answers_count!
- Answer.find_each do |answer|
- UserTopicInfo.answer_added!(answer)
- UserTopicInfo.update_vote_balance!(answer)
+ SearchResult.find_each do |sr|
+ UserTopicInfo.answer_added!(sr)
+ UserTopicInfo.update_vote_balance!(sr)
end
end
@@ -48,6 +48,7 @@ namespace :news_items do
activity_at_hash[nu.id] = nu.entry.activity_at
end
NewsItem.find_each(:batch_size => 1_000,
+ :entry_activity_at => nil,
:news_update_entry_type => "Question") do |ni|
print '.'
ni.set(:entry_activity_at => activity_at_hash[ni.news_update_id])

0 comments on commit ce59a0f

Please sign in to comment.