wagtail-nest / wagtail-review

A Wagtail extension for gathering annotations and feedback on pages before publication
BSD 3-Clause "New" or "Revised" License
49 stars 19 forks source link

the review menu is loading very slowly if we have many reviews #43

Open oladhari opened 2 years ago

oladhari commented 2 years ago

the review menu which is being initiated through this code in wagtail_hooks.py

class ReviewsMenuItem(MenuItem):
    def is_shown(self, request):
        return bool(Review.get_pages_with_reviews_for_user(request.user))

@hooks.register('register_admin_menu_item')
def register_images_menu_item():
    return ReviewsMenuItem(
        _('Reviews'), reverse('wagtail_review_admin:dashboard'),
        name='reviews', classnames='icon icon-tick', order=1000
    )

when checking the code for get_pages_with_reviews_for_user():

    @classmethod
    def get_pages_with_reviews_for_user(cls, user):
        """
        Return a queryset of pages which have reviews, for which the user has edit permission
        """
        user_perms = UserPagePermissionsProxy(user)
        reviewed_pages = (
            cls.objects
            .order_by('-created_at')
            .values_list('page_revision__page_id', 'created_at')
        )
        # Annotate datetime when a review was last created for this page
        last_review_requested_at = Case(
            *[
                When(pk=pk, then=Value(created_at))
                for pk, created_at in reviewed_pages
            ],
            output_field=models.DateTimeField(),
        )
        return (
            user_perms.editable_pages()
            .filter(pk__in=(page[0] for page in reviewed_pages))
            .annotate(last_review_requested_at=last_review_requested_at)
            .order_by('-last_review_requested_at')
        )

as you remark if we have many pages which is my case this loop is causing problems loading any page in the application with menu_items to resolve this problem for the moment I was pushed to delete the hook through this command(because hiding the menu_item is not resolving the problem as the hook is always have been called):

sed -i "s/register_admin_menu_item//g" /usr/local/lib/python3.8/site-packages/wagtail_review/wagtail_hooks.py

my question is there any way to cancel showing the menu item with a more proper way? thank you

oladhari commented 1 month ago

@gasman the description of this issue is not clear? can you have a look if you do not mind if you need more explanation I can add more details