my_forum 0.0.1.beta46 → 0.0.1.beta47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b33c4cb82573653aa48a66e05ffa1d5b1046183
|
4
|
+
data.tar.gz: aed7d3f0d1e8dd3f1ef10ccb29bd85d2bd758322
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
22
|
+
|
20
23
|
LIMIT 1
|
21
24
|
").first
|
22
25
|
end
|
data/app/models/my_forum/post.rb
CHANGED
@@ -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.
|
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
|
data/lib/my_forum/version.rb
CHANGED