Skip to content

Commit

Permalink
Avoid db access to compute the width of the id column
Browse files Browse the repository at this point in the history
  • Loading branch information
agateau committed Jan 23, 2017
1 parent 77b468d commit 1645e7e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions yokadi/ycli/textlistrenderer.py
Expand Up @@ -7,12 +7,9 @@
@license: GPL v3 or later
"""
from datetime import datetime, timedelta
from sqlalchemy.sql import func

import yokadi.ycli.colors as C
from yokadi.core import ydateutils
from yokadi.core import db
from yokadi.core.db import Task
from yokadi.ycli import tui


Expand Down Expand Up @@ -203,6 +200,8 @@ def __init__(self, out, termWidth=None, cryptoMgr=None, renderAsNotes=False, spl
self.idColumn = self.columns[0]
self.titleColumn = self.columns[1]

self.maxId = 0

def addTaskList(self, sectionName, taskList):
"""Store tasks for this section
@param sectionName: name of the task groupment section
Expand All @@ -221,12 +220,12 @@ def addTaskList(self, sectionName, taskList):
if task.description:
titleWidth += 1
self.maxTitleWidth = max(self.maxTitleWidth, titleWidth)
self.maxId = max(self.maxId, task.id)

def end(self):
today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
# Adjust idColumn
maxId = db.getSession().query(func.max(Task.id)).one()[0]
self.idColumn.width = max(2, len(str(maxId)))
self.idColumn.width = max(2, len(str(self.maxId)))

# Adjust titleColumn
self.titleColumn.width = self.maxTitleWidth
Expand Down

0 comments on commit 1645e7e

Please sign in to comment.