# Discourse AI 管理员使用页面 - 自定义日期范围问题

**URL:** https://meta.discourse.org/t/discourse-ai-admin-usage-page-custom-date-range-issues/378959
**Category:** Bug
**Tags:** ai, fixed
**Created:** [2025年八月17日 22:54 UTC](https://meta.discourse.org/t/discourse-ai-admin-usage-page-custom-date-range-issues/378959 "2025-08-17T22:54:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [2025年八月17日 22:54 UTC](https://meta.discourse.org/t/discourse-ai-admin-usage-page-custom-date-range-issues/378959/1 "2025-08-17T22:54:07Z")

</div>

## ℹ 概述

## Discourse AI 使用页面问题

在使用 Discourse AI 管理员 - 使用页面和自定义日期范围功能时，对于不包含当前默认范围的日期，在生成初始结果时会出现某种错误。必须重新选择日期范围参数并刷新两次才能获得正确的结果。

例如，在 [ask.discourse.org](http://ask.discourse.org) 上使用 Discourse AI 管理员使用页面，如果我选择日期范围 2025-07-01T07:00:00Z→2025-07-31T07:00:00Z 然后点击刷新按钮，我只会得到部分结果，这些结果似乎来自比当前日期早一个月的日期范围，并且使用数字也不正确。我必须选择一个六月份的开始日期然后刷新，然后再次选择七月一日并刷新，才能获得正确的结果。但即使那样，有时它也不会立即渲染，只有一半显示出来，特别是当有很多模型时（这在 Meta 上会发生）。我在多个实例上重现了相同的问题。

## 🚶‍♀️ 复现步骤

1. 转到 `admin -> AI -> usage` 页面 (`myforum/admin/plugins/discourse-ai/ai-usage`)
2. 点击 `Custom...` 按钮使用自定义日期范围选择器
3. 选择一个比当前默认范围早的日期范围，例如 2025 年 7 月 1 日 - 2025 年 7 月 31 日，然后点击 `Refresh` 按钮
4. 注意由此产生的错误摘要数字和使用图表日期范围  
 ![image](https://global.discourse-cdn.com/meta/original/4X/8/1/8/8188739b667aefa14c0f360c59c96e23c62bd53a.png)  
 ![image](https://global.discourse-cdn.com/meta/original/4X/6/8/a/68a196a133d3bb74a89374bdd7a577c5972490b6.png)
5. 重新选择一个更早的开始日期，例如 6 月 28 日，然后再次点击 `Refresh` 按钮。
6. 重新选择您想要的原始开始日期，在这种情况下是 2025 年 7 月 1 日，然后再次点击 `Refresh` 按钮。
7. 查看正确的结果！  
 ![image](https://global.discourse-cdn.com/meta/original/4X/b/8/1/b81d152662956a7104bcc28208e6121dc83ad04d.png)  
 ![image](https://global.discourse-cdn.com/meta/original/4X/0/b/f/0bf0609d4c1ec9353df20bef6d6865f50d14aa69.png)

## ✅ 预期结果

首次刷新时，所选自定义日期范围应显示正确的结果。无需重新选择日期或多次刷新。

---

<div class="post-metadata">

### Author: ![keegan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/keegan/32/383395_2.png) [@keegan](https://meta.discourse.org/u/keegan)
#### Post date: [2025年九月16日 18:48 UTC](https://meta.discourse.org/t/discourse-ai-admin-usage-page-custom-date-range-issues/378959/4 "2025-09-16T18:48:51Z")

</div>

🎉 截至此更新，此问题现已解决：

> <https://github.com/discourse/discourse/pull/34816>
>
> \## :mag: Overview 
> Fixes custom date range functionality in AI usage admin page… where:
> - Users experienced visual glitches when selecting dates
> - Date picker would show incorrect dates after refresh
> - Users had to refresh multiple times to get correct date range
> 
> \*\*Changes:\*\*
> - Added fromDate/toDate getters with fallback logic for preview functionality
> - Updated DateTimeInputRange to use preview-aware getters
> - Clear temporary dates after refresh to prevent stale state
> - Added system test to prevent regression
> 
> The date picker now immediately shows selected dates (preview) and
> maintains correct values after refresh, eliminating user confusion.
> 
> This addresses the exact issue reported in \[the meta topic\](https://meta.discourse.org/t/discourse-ai-admin-usage-page-custom-date-range-issues/378959) and provides a clean solution with test coverage to prevent regression.

---

<div class="post-metadata">

### Author: ![keegan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/keegan/32/383395_2.png) [@keegan](https://meta.discourse.org/u/keegan)
#### Post date: [2025年九月17日 15:00 UTC](https://meta.discourse.org/t/discourse-ai-admin-usage-page-custom-date-range-issues/378959/6 "2025-09-17T15:00:08Z")

</div>

此主题已在 20 小时后自动关闭。不再允许回复。
