def pgcalc(sa_session, id, dryrun=False):
 sql_calc = 'SELECT COALESCE(SUM(total_size), 0)\n                  FROM (  SELECT DISTINCT ON (d.id) d.total_size, d.id\n                          FROM history_dataset_association hda\n                               JOIN history h ON h.id = hda.history_id\n                               JOIN dataset d ON hda.dataset_id = d.id\n                          WHERE h.user_id = :id\n                                AND h.purged = false\n                                AND hda.purged = false\n                                AND d.purged = false\n                                AND d.id NOT IN (SELECT dataset_id\n                                                 FROM library_dataset_dataset_association)\n                  ) sizes'
 sql_update = ('UPDATE galaxy_user\n                    SET disk_usage = (%s)\n                    WHERE id = :id\n                    RETURNING disk_usage;' % sql_calc)
 if dryrun:
  r = sa_session.execute(sql_calc, {'id': id})
 else:
  r = sa_session.execute(sql_update, {'id': id})
 return r.fetchone()[0]

def pgcalc ( sa_session , id , dryrun = False ) : sql_calc = 'SELECT COALESCE(SUM(total_size), 0)\n                  FROM (  SELECT DISTINCT ON (d.id) d.total_size, d.id\n                          FROM history_dataset_association hda\n                               JOIN history h ON h.id = hda.history_id\n                               JOIN dataset d ON hda.dataset_id = d.id\n                          WHERE h.user_id = :id\n                                AND h.purged = false\n                                AND hda.purged = false\n                                AND d.purged = false\n                                AND d.id NOT IN (SELECT dataset_id\n                                                 FROM library_dataset_dataset_association)\n                  ) sizes' sql_update = ( 'UPDATE galaxy_user\n                    SET disk_usage = (%s)\n                    WHERE id = :id\n                    RETURNING disk_usage;' % sql_calc ) if dryrun : r = sa_session . execute ( sql_calc , { 'id' : id } ) else : r = sa_session . execute ( sql_update , { 'id' : id } ) return r . fetchone ( ) [ 0 ]
utility method for quickly recalculating user disk usage in postgres .