'Return byte count total of disk space used by all non-purged, non-library
HDAs in non-purged histories.'

def calculate_disk_usage(self):

    dataset_ids = []
    total = 0
    db_session = object_session(self)
    for history in db_session.query(History).enable_eagerloads(False).filter_by(user_id=self.id, purged=False).yield_per(1000):
        for hda in db_session.query(HistoryDatasetAssociation).enable_eagerloads(False).filter_by(history_id=history.id, purged=False).yield_per(1000):
            if ((hda.dataset.id not in dataset_ids) and (not hda.dataset.purged) and (not hda.dataset.library_associations)):
                dataset_ids.append(hda.dataset.id)
                total += hda.dataset.get_total_size()
    return total
