WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.35k stars 4.13k forks source link

Growing database due to unnecessary transients containing "g_url_details_response_" #50571

Open davidki11 opened 1 year ago

davidki11 commented 1 year ago

Description

I created 2 external links in the block editor. This created 2 different transients in the database in wp_options, that have a different dynamic part at the end:

_site_transient_g_url_details_response_ab62baf1c770821f259d255001f7a9b9
_site_transient_g_url_details_response_f6ce245428f26d29c355a44ceb3b9bf3

The value of such created transient is the large part of the html from URL to which I link.

I only want to add some external link in gutenberg editor. Why on earth is necessary to parse the html from URL to which I link?

What if I will have for example 20 external affiliate links on one page and I will have 1000 such pages?

This will unnecessarily bloat the database with useless and unnecessary data!

How can I prevent the creation of transients whose name part contains "g_url_detailsresponse"?

I tryed it using this filter: apply_filters( "pre_set_site_transient_{$transient}", mixed $value, string $transient )

But it needs full transient name, which is created dynamically using this function

private function build_cache_key_for_url( $url ) {
    return 'g_url_details_response_' . md5( $url );
}

from file class-wp-rest-url-details-controller.php

So please remove these pointless transients from wordpress or give users a way to prevent them from being created!

According to me, there is no need at all to create such transients. We only want to add some external links in editor and for that we do not need to parse any additional data.

Please, wordpress developers, start dealing mainly with wordpress optimization in terms of its speed, code redundancy and think about whether what you save in the database is really necessary to save there.

This problem was originally stated on wordpress track here:

Thank you for any reply,

david

Step-by-step reproduction instructions

  1. In gutenberg block editor add some external links.
  2. Go to database and look in to the wordpress table wp_options
  3. Here find transients whose name part contains "g_url_detailsresponse".

Screenshots, screen recording, code snippet

No response

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

aristath commented 1 year ago

Please, wordpress developers, start dealing mainly with wordpress optimization in terms of its speed, code redundancy and think about whether what you save in the database is really necessary to save there.

These transients are actually a performance necessity... Without them, the site would do multiple requests to external URLs to get their contents as was pointed out in the trac ticket. These transients have a timeout of 1h, so if after 1 hour they are no longer necessary, they get automatically deleted. You don't need to do anything, they will be automatically purged from your database! You could make the duration of these transients shorter if you prefer (using the rest_url_details_cache_expiration filter), but disabling them would be detrimental to the performance of the site!

davidki11 commented 1 year ago

I understant that these transients are actually a performance necessity if you decided to parse unnecessary content from external websites.

My post was only about the fact that when I want to insert an external link in the block editor, there is no need to parse anything at all!

I tryed to comment out lines in file rest-api.php (wordpress/wp-includes/) :

// URL Details.
//$controller = new WP_REST_URL_Details_Controller();
//$controller->register_routes();

When I add external link in the gutenberg editor now, the editor works noticeably faster! Just because there is no parsing of useless data, no transients.

When I add external link in the classic editor, there are no additional data needs to be parsed. And in the gutenberg editor is the same situation.

When a user inserts an external link, he doesn't need to see any fancy logo or another description from website to which he link. User know where he link and see this external link when he click on it.

It means no additional data parsed, no needs for unnecessary storage of transients.

Gutenberg already generates such monstrous code by itself that it's a disaster!!! Just like all other wordpress pagebuilders.

So stop putting nonsense in the database that is not needed at all!

Thanks,

david