Improve performance by JOINing postings when extracting transactions
This commit is contained in:
parent
e3900589e6
commit
2e5ae4c20b
@ -41,7 +41,7 @@ def tax_summary_report():
|
||||
# Get trial balance
|
||||
balancer = TrialBalancer()
|
||||
#balancer.apply_transactions(all_transactions())
|
||||
balancer.apply_transactions(db.session.scalars(db.select(Transaction)).all())
|
||||
balancer.apply_transactions(db.session.scalars(db.select(Transaction).options(db.selectinload(Transaction.postings))).all())
|
||||
|
||||
accounts = dict(sorted(balancer.accounts.items()))
|
||||
|
||||
|
@ -27,10 +27,12 @@ from datetime import datetime
|
||||
|
||||
@app.route('/journal')
|
||||
def journal():
|
||||
transactions = db.session.scalars(db.select(Transaction).options(db.selectinload(Transaction.postings)).order_by(Transaction.dt)).all()
|
||||
|
||||
return render_template(
|
||||
'journal/journal.html',
|
||||
commodity_detail=request.args.get('commodity-detail', '0') == '1',
|
||||
transactions=sorted(Transaction.query.all(), key=lambda t: t.dt)
|
||||
transactions=transactions
|
||||
)
|
||||
|
||||
@app.route('/journal/new-transaction', methods=['GET', 'POST'])
|
||||
|
@ -24,12 +24,15 @@ from .models import StatementLine, StatementLineReconciliation
|
||||
|
||||
@app.route('/statement-lines')
|
||||
def statement_lines():
|
||||
if 'account' in request.args:
|
||||
statement_lines = db.select(StatementLine).where(StatementLine.source_account == request.args['account']).order_by(StatementLine.dt)
|
||||
else:
|
||||
statement_lines = db.select(StatementLine).order_by(StatementLine.dt)
|
||||
# JOIN all associated postings (called in is_complex/charge_account)
|
||||
statement_lines = db.select(StatementLine).options(
|
||||
db.joinedload(StatementLine.reconciliation).joinedload(StatementLineReconciliation.posting).joinedload(Posting.transaction).joinedload(Transaction.postings)
|
||||
).order_by(StatementLine.dt)
|
||||
|
||||
page = db.paginate(statement_lines, per_page=request.args.get('per_page', 100))
|
||||
if 'account' in request.args:
|
||||
statement_lines = statement_lines.where(StatementLine.source_account == request.args['account'])
|
||||
|
||||
page = db.paginate(statement_lines, per_page=int(request.args.get('per_page', 1000)))
|
||||
|
||||
return render_template('statements/statement_lines.html', page=page)
|
||||
|
||||
|
@ -30,8 +30,11 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///drcr.db'
|
||||
app.config['SQLALCHEMY_RECORD_QUERIES'] = app.debug
|
||||
db.init_app(app)
|
||||
|
||||
def all_transactions():
|
||||
def all_transactions(join_postings=True):
|
||||
# All Transactions in database
|
||||
if join_postings:
|
||||
transactions = db.session.scalars(db.select(Transaction).options(db.selectinload(Transaction.postings))).all()
|
||||
else:
|
||||
transactions = db.session.scalars(db.select(Transaction)).all()
|
||||
|
||||
# Unreconciled StatementLines
|
||||
|
Loading…
Reference in New Issue
Block a user