Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
diaspora
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Milan
diaspora
Commits
0ffb83d3
Commit
0ffb83d3
authored
Jun 04, 2015
by
Benjamin Neff
Committed by
Dennis Schubert
Jun 08, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
load conversations and visibilities in one query with correct order
parent
735d692a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
23 deletions
+29
-23
app/controllers/conversations_controller.rb
app/controllers/conversations_controller.rb
+26
-20
app/models/user.rb
app/models/user.rb
+2
-2
app/views/conversations/index.haml
app/views/conversations/index.haml
+1
-1
No files found.
app/controllers/conversations_controller.rb
View file @
0ffb83d3
...
...
@@ -5,35 +5,41 @@ class ConversationsController < ApplicationController
respond_to
:html
,
:mobile
,
:json
,
:js
def
index
@
conversations
=
current_user
.
conversations
.
paginate
(
:page
=>
params
[
:page
],
:per_page
=>
15
)
@visibilities
=
current_user
.
conversation_visibilities
.
paginate
(
:page
=>
params
[
:page
],
:per_page
=>
15
)
@conversation
=
Conversation
.
joins
(
:conversation_visibilities
).
where
(
:conversation_visibilities
=>
{
:person_id
=>
current_user
.
person_id
,
:conversation_id
=>
params
[
:conversation_id
]}).
first
@unread_counts
=
{}
@visibilities
.
each
{
|
v
|
@unread_counts
[
v
.
conversation_id
]
=
v
.
unread
}
@first_unread_message_id
=
@conversation
.
try
(
:first_unread_message
,
current_user
).
try
(
:id
)
if
@conversation
@conversation
.
set_read
(
current_user
)
@
visibilities
=
ConversationVisibility
.
includes
(
:conversation
)
.
order
(
"conversations.updated_at DESC"
)
.
where
(
person_id:
current_user
.
person_id
)
.
paginate
(
page:
params
[
:page
],
per_page:
15
)
if
params
[
:conversation_id
]
@conversation
=
Conversation
.
joins
(
:conversation_visibilities
)
.
where
(
conversation_visibilities:
{
person_id:
current_user
.
person_id
,
conversation_id:
params
[
:conversation_id
]
}).
first
if
@conversation
@first_unread_message_id
=
@conversation
.
first_unread_message
(
current_user
).
try
(
:id
)
@conversation
.
set_read
(
current_user
)
end
end
@conversations
=
[]
@unread_counts
=
{}
@authors
=
{}
@conversations
.
each
{
|
c
|
@authors
[
c
.
id
]
=
c
.
last_author
}
@ordered_participants
=
{}
@conversations
.
each
{
|
c
|
@ordered_participants
[
c
.
id
]
=
(
c
.
messages
.
map
{
|
m
|
m
.
author
}.
reverse
+
c
.
participants
).
uniq
}
@visibilities
.
each
{
|
v
|
@unread_counts
[
v
.
conversation_id
]
=
v
.
unread
c
=
v
.
conversation
@conversations
<<
c
@authors
[
c
.
id
]
=
c
.
last_author
@ordered_participants
[
c
.
id
]
=
(
c
.
messages
.
map
(
&
:author
).
reverse
+
c
.
participants
).
uniq
}
gon
.
contacts
=
contacts_data
respond_with
do
|
format
|
format
.
html
format
.
json
{
render
:json
=>
@conversations
,
:status
=>
200
}
format
.
json
{
render
json:
@conversations
,
status:
200
}
end
end
...
...
app/models/user.rb
View file @
0ffb83d3
...
...
@@ -67,8 +67,8 @@ class User < ActiveRecord::Base
has_many
:blocks
has_many
:ignored_people
,
:through
=>
:blocks
,
:source
=>
:person
has_many
:conversation_visibilities
,
->
{
order
'updated_at DESC'
},
through: :person
has_many
:conversations
,
->
{
order
'updated_at DESC'
},
through: :conversation_visibilities
has_many
:conversation_visibilities
,
through: :person
has_many
:conversations
,
through: :conversation_visibilities
has_many
:notifications
,
:foreign_key
=>
:recipient_id
...
...
app/views/conversations/index.haml
View file @
0ffb83d3
...
...
@@ -21,7 +21,7 @@
-
else
#no_conversations
=
t
(
'.no_messages'
)
=
will_paginate
@
conversations
,
:previous_label
=>
'«'
,
:next_label
=>
'»'
,
:inner_window
=>
1
,
:renderer
=>
WillPaginate
::
ActionView
::
BootstrapLinkRenderer
=
will_paginate
@
visibilities
,
:previous_label
=>
"«"
,
:next_label
=>
"»"
,
:inner_window
=>
1
,
:renderer
=>
WillPaginate
::
ActionView
::
BootstrapLinkRenderer
.span8
-
if
@conversation
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment