Skip to content

amp_admin_get_preview_permalink throws query everywhere in Dashboard #3684

@fumikito

Description

@fumikito

Bug Description

AMP plugin create preview link in admin menu with function amp_admin_get_preview_permalink
But it makes get_posts call which costs a lot especially in WordPress with many posts:

$post_ids = get_posts(
[
'no_found_rows' => true,
'suppress_filters' => false,
'post_status' => 'publish',
'post_password' => '',
'post_type' => $supported_post_types,
'posts_per_page' => 1,
'fields' => 'ids',
// @todo This should eventually do a meta_query to make sure there are none that have AMP_Post_Meta_Box::STATUS_POST_META_KEY = DISABLED_STATUS.
]
);

As a result, users face slow page loads on every admin page.
In my case, the query costs almost 3 seconds.

Expected Behaviour

  1. Customizer link should be always same(e.g. https://example.com/wp-admin/customizer.php)
  2. In customizer page of amp, default permalink which amp_admin_get_preview_permalink expected to retrieve will be applied.

Steps to reproduce

  1. Install WordPress and put 10,000 posts by 100 users in 3 custom post types.
  2. Install and activate AMP & Query Monitor.
  3. Open admin page and confirm slow query runs at every page.

Screenshots

スクリーンショット 2019-11-05 13 33 49

Additional context

  • WordPress version: 5.2.4
  • Plugin version: 1.4.0
  • Gutenberg plugin version (if applicable):
  • AMP plugin template mode:
  • PHP version: 7.2
  • OS: Amazon Linux
  • Browser: Chrome
  • Device: Macbook Pro

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

  • Set AMP website mode to 'Reader' (so that the AMP Customizer menu item is shown):

    Screenshot

  • Clicking on it should send you to the homepage, and not the first AMP compatible post

Demo

Changelog entry

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingPerformanceQA passedHas passed QA and is done

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions