Commit b73d74c2 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Avoid cross-DB join

parent 80576418
Pipeline #20528 passed with stages
in 3 minutes and 54 seconds
......@@ -2,14 +2,14 @@ import logging
from flask import Blueprint, render_template, request, redirect, url_for, abort, session
from acoustid.web import db
from acoustid.web.utils import require_user
from acoustid.models import TrackMBIDChange, TrackMeta, Meta
from acoustid.models import TrackMBIDChange, TrackMeta, Meta, Account, TrackMBID
from import resolve_track_gid
from import lookup_recording_metadata
from import is_moderator
from acoustid.utils import is_uuid
from acoustid import tables as schema
from sqlalchemy import sql
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import load_only
logger = logging.getLogger(__name__)
......@@ -78,11 +78,29 @@ def track(track_id_or_gid):
edits = db.session.query(TrackMBIDChange).\
options(joinedload('account', innerjoin=True).load_only('mbuser', 'name')).\
options(joinedload('track_mbid', innerjoin=True).load_only('mbid')).\
filter(TrackMBIDChange.track_mbid_id.in_( for m in mbids)).\
edits_accounts = db.session.query(Account).options(load_only('mbuser', 'name')).\
filter( for e in edits)).all()
edits_accounts_by_id = {}
for account in edits_accounts:
edits_accounts_by_id[] = account
edits_track_mbids = db.session.query(TrackMBID).options(load_only('mbid')).\
filter( for e in edits)).all()
edits_track_mbids_by_id = {}
for track_mbid in edits_track_mbids:
edits_track_mbids_by_id[] = track_mbid
for edit in edits:
account = edits_accounts_by_id.get(edit.account_id)
if account is not None:
edit.account = account
track_mbid = edits_track_mbids_by_id.get(edit.track_mbid_id)
if track_mbid is not None:
edit.track_mbid = track_mbid
moderator = is_moderator(db.get_app_db(), session.get('id'))
return render_template('track.html', title=title,
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment