Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
oladhari opened this issue Dec 15, 2021 · 0 comments
Open

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

oladhari opened this issue Dec 15, 2021 · 0 comments

Comments

@oladhari
Copy link

oladhari commented Dec 15, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant