Do not use RDMBS dependent function
This commit is contained in:
parent
4ed28e04e3
commit
7d9a42b82c
|
@ -3,6 +3,7 @@ from orator.orm import Model
|
|||
from orator.orm import belongs_to
|
||||
from orator.orm import has_many
|
||||
|
||||
from src.utils import random_element
|
||||
import src.entity.reply
|
||||
import src.entity.chat
|
||||
import src.entity.word
|
||||
|
@ -31,7 +32,7 @@ class Pair(Model):
|
|||
@staticmethod
|
||||
def get_random_pair(chat_id, first_id, second_id_list):
|
||||
ten_minutes_ago = datetime.now() - timedelta(seconds=10 * 60)
|
||||
return Pair\
|
||||
pairs = Pair\
|
||||
.with_({
|
||||
'replies': lambda q: q.order_by('count', 'desc').limit(3)
|
||||
})\
|
||||
|
@ -39,5 +40,8 @@ class Pair(Model):
|
|||
.where('first_id', first_id)\
|
||||
.where_in('second_id', second_id_list)\
|
||||
.where('created_at', '<', ten_minutes_ago)\
|
||||
.order_by_raw('RANDOM()')\
|
||||
.first()
|
||||
.limit(3)\
|
||||
.get()\
|
||||
.all()
|
||||
|
||||
return random_element(pairs)
|
||||
|
|
Loading…
Reference in New Issue