-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use last_activity_at instead of updated_at for sorting (#1281)
Co-authored-by: Akash Srivastava <[email protected]>
- Loading branch information
1 parent
ee119b2
commit 399f9e0
Showing
11 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
db/migrate/20200927135222_add_last_activity_at_to_conversation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class AddLastActivityAtToConversation < ActiveRecord::Migration[6.0] | ||
def up | ||
add_column :conversations, | ||
:last_activity_at, | ||
:datetime, | ||
default: -> { 'CURRENT_TIMESTAMP' }, | ||
index: true | ||
|
||
add_last_activity_at_to_conversations | ||
|
||
change_column_null(:conversations, :last_activity_at, false) | ||
end | ||
|
||
def down | ||
remove_column(:conversations, :last_activity_at) | ||
end | ||
|
||
private | ||
|
||
def add_last_activity_at_to_conversations | ||
::Conversation.find_in_batches do |conversation_batch| | ||
Rails.logger.info "Migrated till #{conversation_batch.first.id}\n" | ||
conversation_batch.each do |conversation| | ||
# rubocop:disable Rails/SkipsModelValidations | ||
last_activity_at = if conversation.messages.last | ||
conversation.messages.last.created_at | ||
else | ||
conversation.created_at | ||
end | ||
conversation.update_columns(last_activity_at: last_activity_at) | ||
# rubocop:enable Rails/SkipsModelValidations | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters