Skip to content

Commit

Permalink
fixed order users on list
Browse files Browse the repository at this point in the history
  • Loading branch information
raphox committed Jun 17, 2020
1 parent 549ce91 commit 08ac2ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ def show
end

# FIXME: Change this When use ACTIVE_MODEL_CLASS as UserNeo4j
@friends = User.where(:neo4j_uuid.in => friends.pluck(:uuid))
uuids = friends.map { |node| node.props[:uuid] || node.uuid }
@friends = User.where(:neo4j_uuid.in => friends.pluck(:uuid)).
to_a.sort_by { |value| uuids.index(value.neo4j_uuid) } # preserving order

@friends_path = friends_path&.transform_values do |item|
uuids = item.map { |node| node.props[:uuid] || node.uuid }

# it is necessary to order after query in database to preser correct path
User.where(:neo4j_uuid.in => uuids).
to_a.sort_by { |value| uuids.index(value.neo4j_uuid) }
to_a.sort_by { |value| uuids.index(value.neo4j_uuid) } # preserving order
end
end

Expand Down
1 change: 0 additions & 1 deletion app/models/user_neo4j.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def friends_by_search(term)

total += (friends_path[item.uuid].length - 2) * 10
total += item.titles.any? { titles.include?(term) } ? -10 : 0
total += item.subtitles.any? { |subtitle| subtitle.include?(term) } ? -5 : 0

total
end
Expand Down

0 comments on commit 08ac2ba

Please sign in to comment.