Unverified Commit 78567b54 authored by davelopez's avatar davelopez
Browse files

Improve count request performance

Unless I'm mistaken doing the count at the database level should be faster than retrieving all histories and then check the length.
parent 4fff3677
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -403,6 +403,15 @@ class HistoryManager(sharable.SharableModelManager, deletable.PurgableManagerMix

        return history

    def get_active_count(self, user: model.User) -> int:
        """Return the number of active histories for the given user."""
        user_active_histories_filter = [
            model.History.user_id == user.id,
            model.History.deleted == false(),
            model.History.archived == false(),
        ]
        return self.count(filters=user_active_histories_filter)


class HistoryStorageCleanerManager(StorageCleanerManager):
    def __init__(self, history_manager: HistoryManager):
+2 −4
Original line number Diff line number Diff line
@@ -476,10 +476,8 @@ class HistoriesService(ServiceBase, ConsumesModelStores, ServesExportStores):
        current_user = self.user_manager.current_user(trans)
        if self.user_manager.is_anonymous(current_user):
            current_history = self.manager.get_current(trans)
            if not current_history:
                return 0
            return 1
        return len(current_user.active_histories)
            return 1 if current_history else 0
        return self.manager.get_active_count(current_user)

    def published(
        self,