站点地图:`lastmod`错误

主站点地图中,下级站点地图的 lastmod 日期不正确:

例如,请参见 https://meta.discourse.org/sitemap.xml
sitemap_2.xmlsitemap_5.xml 的日期均为 ‘2024-03-14T14:02:32Z’ - 这正是“3 天前”。

<sitemapindex>
    <sitemap>
        <loc>https://meta.discourse.org/sitemap_recent.xml</loc>
        <lastmod>2024-03-17T14:02:29Z</lastmod>
    </sitemap>
    <sitemap>
        <loc>https://meta.discourse.org/sitemap_1.xml</loc>
        <lastmod>2024-03-17T14:02:29Z</lastmod>
    </sitemap>
    <sitemap>
        <loc>https://meta.discourse.org/sitemap_2.xml</loc>
        <lastmod>2024-03-14T14:02:32Z</lastmod>
    </sitemap>
    <sitemap>
        <loc>https://meta.discourse.org/sitemap_3.xml</loc>
        <lastmod>2024-03-14T14:02:32Z</lastmod>
    </sitemap>
    <sitemap>
        <loc>https://meta.discourse.org/sitemap_4.xml</loc>
        <lastmod>2024-03-14T14:02:32Z</lastmod>
    </sitemap>
    <sitemap>
        <loc>https://meta.discourse.org/sitemap_5.xml</loc>
        <lastmod>2024-03-14T14:02:32Z</lastmod>
    </sitemap>
</sitemapindex>

技术问题:

不知何故,sitemap_[2-5].xml 使用了 3.days.ago,因为 sitemap.last_posted_topic 可能未返回有效值。

另一点:在 last_posted_topic 中也使用 bumped_at

与主题站点地图 sitemap_[1-5].xml 本身的 lastmod 进行比较:

未经测试的伪代码:

    def last_posted_topic
      [sitemap_topics.maximum(:bumped_at), sitemap_topics.maximum(:updated_at)].max
    end

我担心这里的优化会极大地增加复杂性,但收益却微乎其微。

仔细想想……

假设元数据中有 6 个块。如果触及了最后一个块中的某个主题……整个块都会变得无效,你必须将该主题从那里移除,然后放到第一个块中。

对于有任何活动的网站来说,在这里进行优化有点毫无意义,而且块中关于实际主题的日期也很好。

1 个赞

这不是将主题移入不同的站点地图块。主题可以保留在它们已有的同一个站点地图块中。
(主题到站点地图块的映射无论如何都是任意的,因为数据库 select 语句带有 limit 没有定义 order。)

此 bug 报告是关于每个站点地图块的 lastmod 日期应代表该站点地图块包含的最新主题的 lastmod 日期。

Google 的方式应该是:

  1. 加载 sitemap.xml
  • 检查站点地图块的 lastmod 并排队需要更新的站点地图块
    lastmod 日期比上次下载日期新)
  1. 加载排队的站点地图块 sitemap_[1-5].xml
  • 检查主题 URL 的 lastmod 并排队需要更新的主题 URL
    lastmod 日期比上次下载日期新)
  1. 加载排队的主题 URL。

如果 sitemap.xml 中站点地图块的 lastmod 是错误的:

  • Google 不会排队更改的站点地图块(步骤 1)
  • Google 不会及时更新更改的站点地图块(步骤 2)
  • Google 不会及时更新更改的主题(步骤 3)

目前 https://meta.discourse.org/sitemap.xml 看起来是这样的:

  • https://meta.discourse.org/sitemap_1.xml
    lastmod: 2024-03-19T12:50:09Z
    内部所有主题的日期都更旧或相同? :github_check:

    • 最新主题: https://meta.discourse.org/t/creating-a-stickypost-for-forum-threads/299967
      lastmod: 2024-03-19T11:03:38Z
  • https://meta.discourse.org/sitemap_2.xml
    lastmod: 2024-03-16T12:59:17Z
    内部所有主题的日期都更旧或相同? :x:

    • 最新主题: https://meta.discourse.org/t/launcher-rebuild-app-error-bootstrap-failed-with-exit-code-125/299538
      lastmod: 2024-03-19T09:17:46Z
  • https://meta.discourse.org/sitemap_3.xml
    lastmod: 2024-03-16T12:59:17Z
    内部所有主题的日期都更旧或相同? :x:

    • 最新主题: https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites/49487
      lastmod: 2024-03-18T18:16:26Z
  • https://meta.discourse.org/sitemap_4.xml
    lastmod: 2024-03-16T12:59:17Z
    内部所有主题的日期都更旧或相同? :x:

    • 最新主题: https://meta.discourse.org/t/video-thumbnails-issue/263595
      lastmod: 2024-03-19T00:00:20Z
  • https://meta.discourse.org/sitemap_5.xml
    lastmod: 2024-03-16T12:59:17Z
    内部所有主题的日期都更旧或相同? :x:

    • 最新主题: https://meta.discourse.org/t/daily-summary-9pm-utc/291850
      lastmod: 2024-03-18T21:14:49Z
  • https://meta.discourse.org/sitemap_recent.xml
    2024-03-19T13:03:41Z
    内部所有主题的日期都更旧或相同? :github_check:

    • 最新主题: https://meta.discourse.org/t/daily-summary-1pm-utc/291852
      lastmod: 2024-03-19T13:02:07Z

严格来说这并不完全正确……last_mod 的意思是站点地图最后修改的日期,而不是主题的最大日期。

如果一个主题今天从站点地图部分中移除,而该分块的最后修改日期是一周前……那么这个分块今天发生了更改。一个主题今天被移除了。

这是完全正确的。

所以,完全相同的逻辑会导致:
如果站点地图中的一个主题今天发生了变化,并且块中的最后修改时间是今天……那么块今天发生了变化 [注意:不是三天前]。它里面的一个主题今天发生了变化。

对于上面你和我的例子,目前的实现是:
站点地图块 sitemap_[2-5].xml 在三天前发生变化。这是错误的。它应该说“今天发生变化”。

这是这一切的更大图景:

sitemap_recent.xml

  • 仅包含过去 3 天内所有已更改的主题
  • 每 1 小时更新一次(内部 Rails 缓存时间为 1 小时)
  • sitemap.xml 中具有正确的 lastmod 日期

sitemap_[1-5].xml

  • 实际上包含所有主题,还包含过去 3 天内所有已更改的主题
  • 每 24 小时更新一次(内部 Rails 缓存时间为 24 小时)
  • sitemap_[2-5].xmlsitemap.xml 中具有错误的 lastmod 日期 3.days.ago

sitemap_[2-5].xml 的错误 lastmod 日期无关紧要,因为 Google 会及时通过 sitemap_recent.xml 获取所有最近的主题更改。