my_forum 0.0.1.beta46 → 0.0.1.beta47

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b8e08aa2bc1c01ded3147b72abc835493533068
4
- data.tar.gz: 96080563f950816d16e1341416c4fc97536c036b
3
+ metadata.gz: 9b33c4cb82573653aa48a66e05ffa1d5b1046183
4
+ data.tar.gz: aed7d3f0d1e8dd3f1ef10ccb29bd85d2bd758322
5
5
  SHA512:
6
- metadata.gz: 418f5c30b9a38a76a398fe8aa305cfaf43fc9ea4b709b6a09e94562ad41b04a581237a3943abde224c379bdcfc0fdbe9f4f2ea9b5f0d72b2ac9dd900853a7ace
7
- data.tar.gz: cc774917b805e8bbd0eda06254f729a2196ad1c2df1034f68f723c2c5e8342dab1b5821b60bdbb2c70e389b6fac88bebfae133f43ac9ac59b4d84a357c75359b
6
+ metadata.gz: 7e3a752f9498e68cdc9c6df35974fde15c947ba02ad19c8efeb00d0ccb1d0e170d595b75886df92d510c52fee26e0f99b18c86ade254150bf208af2b3c4e738f
7
+ data.tar.gz: f5cb24e415e17ccf7eb6380be754601398f3ce6979a6397cf9cb34fd1c42fa9b02afa1ff489aba2f526859f531a2dcdb6230259c20eb1917c4a5e43333e23b32
@@ -62,7 +62,7 @@ module MyForum
62
62
 
63
63
  # TODO development in progress
64
64
  def get_last_readed_user_page
65
- return nil unless params[:page].blank? or current_user
65
+ return nil unless params[:page].blank? or current_user or @topic
66
66
  user_last_page = nil
67
67
 
68
68
  latest_readed_post = LogReadMark.where(user_id: current_user.id, topic_id: @topic.id).first
@@ -9,14 +9,17 @@ module MyForum
9
9
  SELECT
10
10
  my_forum_topics.name AS topic_name,
11
11
  my_forum_topics.forum_id,
12
+
13
+
12
14
  my_forum_topics.id,
13
- my_forum_posts.created_at AS post_created_at,
14
- my_forum_users.login AS user_login
15
- FROM my_forum_posts
16
- JOIN my_forum_topics ON my_forum_topics.id = my_forum_posts.topic_id
17
- JOIN my_forum_users ON my_forum_posts.user_id = my_forum_users.id
15
+ my_forum_topics.latest_post_created_at AS post_created_at,
16
+ my_forum_topics.latest_post_login AS user_login
17
+
18
+
19
+ FROM my_forum_topics
20
+
18
21
  WHERE my_forum_topics.forum_id = #{self.id}
19
- ORDER BY my_forum_posts.id DESC
22
+
20
23
  LIMIT 1
21
24
  ").first
22
25
  end
@@ -4,6 +4,7 @@ module MyForum
4
4
  belongs_to :user, :counter_cache => true
5
5
 
6
6
  after_create :update_topic_latest_post
7
+ after_update :update_topic_latest_post, :if => :is_deleted?
7
8
 
8
9
  default_scope { where(is_deleted: false) }
9
10
 
@@ -12,7 +13,14 @@ module MyForum
12
13
  private
13
14
 
14
15
  def update_topic_latest_post
15
- self.topic.update_attribute(:latest_post_id, self.id)
16
+ post = self.is_deleted ? Post.where(topic_id: self.topic_id).last : self
17
+
18
+ self.topic.update(
19
+ latest_post_id: post.id,
20
+ latest_post_created_at: post.created_at,
21
+ latest_post_login: post.user.login,
22
+ latest_post_user_id: post.user.id
23
+ )
16
24
  end
17
25
  end
18
26
  end
@@ -2,7 +2,23 @@ class AddLatestPostInfoForTopic < ActiveRecord::Migration
2
2
  def change
3
3
  add_column :my_forum_topics, :latest_post_created_at, :datetime
4
4
  add_column :my_forum_topics, :latest_post_login, :string
5
+ add_column :my_forum_topics, :latest_post_user_id, :integer
5
6
 
7
+ count = MyForum::Topic.count
8
+ MyForum::Topic.find_in_batches do |group|
9
+ group.each do |topic|
10
+ puts "#{count-=1} Try to update #{topic.name}"
11
+ latest_post = topic.posts.last
12
+ latest_post_user = latest_post.user
13
+ next unless latest_post_user
14
+
15
+ topic.update(
16
+ latest_post_created_at: latest_post.created_at,
17
+ latest_post_login: latest_post_user.login,
18
+ latest_post_user_id: latest_post_user.id
19
+ )
20
+ end
21
+ end
6
22
 
7
23
  end
8
24
  end
@@ -1,3 +1,3 @@
1
1
  module MyForum
2
- VERSION = "0.0.1.beta46"
2
+ VERSION = "0.0.1.beta47"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_forum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta46
4
+ version: 0.0.1.beta47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Omelchenko