URL-to-post lookups cache resolutions for a week without invalidation

Abierto
#4,663 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
php, wordpress

Línea de trabajo

Start in src/Utils/class-utils.php at the two cache writes around lines 446 and 481, then trace how get_post_id_by_url() is used and how post-change hooks are registered. Reproduce with a persistent object cache using the steps in the issue, and check existing tests for URL-to-post lookups. Done means changes to a post’s status, slug, or existence cannot leave a stale lookup result across the described paths.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Bug wp-parsely

Describe the bug

Utils::get_post_id_by_url() caches its result under url-to-postid-<hash> for WEEK_IN_SECONDS, in two places: src/Utils/class-utils.php:446 for the url_to_postid() match, and :481 for the slug match. Nothing invalidates that key — there is no wp_cache_delete() for it, and no hook on post changes.

A cached resolution can therefore disagree with the site for up to a week after the post behind a URL changes. Visibility is checked on return, so this is a freshness and correctness issue rather than an access one.

To Reproduce

On a site with a persistent object cache:

  1. Create a private page with the slug example-slug.
  2. Resolve a URL ending in /example-slug/ through any feature that maps URLs to posts, so the result is cached.
  3. Publish a post with the same slug. WordPress keeps slugs unique only within a post type, so a page and a post can share one.
  4. Resolve the same URL again.

The lookup keeps returning the earlier resolution until the entry expires. Clearing the object cache returns the expected post.

The same cause affects neighbouring cases: a cached post that is later unpublished, deleted, or given a different slug.

Expected behavior

The lookup reflects the current state of the site, or the cached entry is invalidated when the posts behind it change.

Environment

wp-parsely 3.24.x, any WordPress version. Only observable on sites with a persistent object cache; without one the entry lasts a single request.

Additional context

Raised by CodeRabbit on #4662.

Possible directions: invalidate the key on save_post/deleted_post, shorten the TTL, or key the entry so that a stale hit cannot occur. Addressing it at a single call site would leave the other paths above untouched.

Lenguaje dominante
PHP
Estrellas
67
Forks
38
Merge medio
1 d 5 h
PR fusionados (30 d)
79

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Parsely/wp-parsely

Todos los issues de Parsely/wp-parsely

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.