Added some order to queries (for postgresql).

This commit is contained in:
Martin Edenhofer 2016-07-12 10:19:28 +02:00
parent 9f8b8d3160
commit 2427677f83
4 changed files with 8 additions and 8 deletions

View file

@ -13,7 +13,7 @@ class Karma::ActivityLog < ApplicationModel
end end
Karma::ActivityLog.transaction do Karma::ActivityLog.transaction do
last_activity = Karma::ActivityLog.where(user_id: user.id).order(id: :desc).lock(true).first last_activity = Karma::ActivityLog.where(user_id: user.id).order(created_at: :desc, id: :desc).lock(true).first
latest_activity = Karma::ActivityLog.where( latest_activity = Karma::ActivityLog.where(
user_id: user.id, user_id: user.id,
object_lookup_id: object_id, object_lookup_id: object_id,

View file

@ -116,7 +116,7 @@ class Transaction::Karma
return if !type.communication return if !type.communication
### answer sent (check last action time / within what time?) ### answer sent (check last action time / within what time?)
articles = Ticket::Article.where(ticket_id: article.ticket_id).order(created_at: :asc) articles = Ticket::Article.where(ticket_id: article.ticket_id).order(created_at: :asc, id: :asc)
if articles.count > 1 if articles.count > 1
last_sender_customer = nil last_sender_customer = nil
last_customer_contact = nil last_customer_contact = nil
@ -142,7 +142,7 @@ class Transaction::Karma
} }
if last_sender_customer && last_customer_contact if last_sender_customer && last_customer_contact
diff = article.created_at - last_customer_contact diff = article.created_at - last_customer_contact
if diff > 0 if diff >= 0
if diff < 1.hour if diff < 1.hour
Karma::ActivityLog.add('ticket answer 1h', user, 'Ticket', @item[:object_id]) Karma::ActivityLog.add('ticket answer 1h', user, 'Ticket', @item[:object_id])
elsif diff < 2.hours elsif diff < 2.hours

View file

@ -13,7 +13,7 @@ class Sessions::Backend::Collections::Base < Sessions::Backend::Base
def load def load
# get whole collection # get whole collection
self.class.model.constantize.all self.class.model.constantize.all.order(id: :asc)
end end
def client_key def client_key

View file

@ -60,7 +60,7 @@ class KarmaTest < ActiveSupport::TestCase
to: 'some_recipient@example.com', to: 'some_recipient@example.com',
subject: 'some subject', subject: 'some subject',
message_id: 'some@id', message_id: 'some@id',
body: 'some message', body: 'agent phone 1 / init',
internal: false, internal: false,
sender: Ticket::Article::Sender.lookup(name: 'Agent'), sender: Ticket::Article::Sender.lookup(name: 'Agent'),
type: Ticket::Article::Type.lookup(name: 'phone'), type: Ticket::Article::Type.lookup(name: 'phone'),
@ -146,7 +146,7 @@ class KarmaTest < ActiveSupport::TestCase
to: 'some_recipient@example.com', to: 'some_recipient@example.com',
subject: 'reply: some subject', subject: 'reply: some subject',
message_id: 'some@id', message_id: 'some@id',
body: 'some message', body: 'agent phone 2',
internal: false, internal: false,
sender: Ticket::Article::Sender.lookup(name: 'Agent'), sender: Ticket::Article::Sender.lookup(name: 'Agent'),
type: Ticket::Article::Type.lookup(name: 'phone'), type: Ticket::Article::Type.lookup(name: 'phone'),
@ -185,7 +185,7 @@ class KarmaTest < ActiveSupport::TestCase
to: 'some_recipient@example.com', to: 'some_recipient@example.com',
subject: 'some subject', subject: 'some subject',
message_id: 'some@id', message_id: 'some@id',
body: 'some message', body: 'customer phone',
internal: false, internal: false,
sender: Ticket::Article::Sender.lookup(name: 'Customer'), sender: Ticket::Article::Sender.lookup(name: 'Customer'),
type: Ticket::Article::Type.lookup(name: 'phone'), type: Ticket::Article::Type.lookup(name: 'phone'),
@ -209,7 +209,7 @@ class KarmaTest < ActiveSupport::TestCase
to: 'some_recipient@example.com', to: 'some_recipient@example.com',
subject: 'some subject', subject: 'some subject',
message_id: 'some@id', message_id: 'some@id',
body: 'some message', body: 'agent phone 3',
internal: false, internal: false,
sender: Ticket::Article::Sender.lookup(name: 'Agent'), sender: Ticket::Article::Sender.lookup(name: 'Agent'),
type: Ticket::Article::Type.lookup(name: 'phone'), type: Ticket::Article::Type.lookup(name: 'phone'),