mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 15:36:18 -05:00
Fixing video search bug.
This commit is contained in:
parent
a95cbd74c9
commit
3f7145c940
2 changed files with 9 additions and 3 deletions
|
|
@ -139,8 +139,9 @@ def video_search(
|
|||
total = results[0]['total'] if results else 0
|
||||
ranked_ids = [i['id'] for i in results]
|
||||
|
||||
results = get_ranked_models(ranked_ids, Video)
|
||||
results = [i.__json__() for i in results]
|
||||
with get_db_session() as session:
|
||||
results = get_ranked_models(ranked_ids, Video, session=session)
|
||||
results = [i.__json__() for i in results]
|
||||
|
||||
return results, total
|
||||
|
||||
|
|
|
|||
|
|
@ -113,10 +113,15 @@ def get_db_curs(commit: bool = False):
|
|||
connection.rollback()
|
||||
|
||||
|
||||
def get_ranked_models(ranked_ids: List[int], model: Base) -> List[Base]:
|
||||
def get_ranked_models(ranked_ids: List[int], model: Base, session: Session = None) -> List[Base]:
|
||||
"""
|
||||
Get all objects whose ids are in the `ranked_ids`, order them by their position in `ranked_ids`.
|
||||
"""
|
||||
if session:
|
||||
results = session.query(model).filter(model.id.in_(ranked_ids)).all()
|
||||
results = sorted(results, key=lambda i: ranked_ids.index(i.id))
|
||||
return results
|
||||
|
||||
with get_db_session() as session:
|
||||
results = session.query(model).filter(model.id.in_(ranked_ids)).all()
|
||||
results = sorted(results, key=lambda i: ranked_ids.index(i.id))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue