Favorites page fetches every favorite because getDaily's guard is inverted
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript
- Lĩnh vực
- frontend, performance
Hướng nghiên cứu
Bắt đầu trong cal/src/support/favorites.js và cal/src/support/dataPool.js, sau đó tái hiện bằng npm run dev với một lần tải trang mới và tab Favorites. Xác minh rằng việc tải mục yêu thích chỉ từ cache không tạo bất kỳ yêu cầu nào đến events.php và rằng các tiêu đề, ngày tháng và thời gian đã lưu vẫn được hiển thị chính xác; kiểm tra docs/CalVue.md để biết hành vi làm mới dự kiến.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Opening the Favorites tab issues one events.php request per stored favorite, one after another, even though the calling code explicitly asks for cache-only data by passing {fetch: false}. The guard it passes that flag to is inverted, so it gets the opposite of what it asks for.
Reproducing
npm run dev, then openhttp://localhost:3080/events/- Open a few rides and favorite each one (the star button on the event details page)
- Reload the page — this matters, see the note below
- Open DevTools → Network and filter for
events.php - Click through to the Favorites tab
Expected: no requests. The favorites list renders from local storage.
Actual: one events.php?id=N request per favorite, each starting only after the previous one finishes.
With 4 favorites stored I measured 4 requests taking 11 ms, 2.1 ms, 1.9 ms and 1.9 ms, starting at +0, +11.3, +13.5 and +15.5 ms — 17.3 ms of wall time on localhost. The start offsets line up with the preceding request's completion, which confirms they are serialised rather than merely issued in quick succession.
The reload in step 3 matters because dataPool keeps an in-memory caldaily_map. If you favorited the rides in the same page session they are already cached, the early-return hides the bug and you see nothing. A fresh load is the normal case anyway — someone opening the app and tapping Favorites.
Cause
cal/src/support/favorites.js asks for cache-only data:
// if we have retrieved this event recently; update it.
// future: background request to update all ( or a page of ) favorite data.
const [ series_id, single_id ] = key.split('-');
const evt = await dataPool.getDaily(single_id, {fetch: false});
But the guard in cal/src/support/dataPool.js is inverted:
async getDaily(caldaily_id, options = null) {
const cached = caldaily_map.get(caldaily_id);
if (cached) {
return cached;
} else if (!options || options.fetch === false) {
// ...performs the network fetch
The branch runs the fetch when fetch is false. Because that await sits inside a for loop over every stored key, the requests are also serialised.
A second consequence: getDaily(id, {fetch: true}) matches neither branch and returns undefined. Nothing calls it that way today, so it is latent rather than broken.
Suggested fix, and the one thing it changes
- } else if (!options || options.fetch === false) {
+ } else if (!options || options.fetch !== false) {
I tried this locally: the Favorites tab makes 0 requests and all four favorites still render correctly, with the right titles, dates and times, straight from local storage.
To be upfront about the trade-off — these requests are not doing nothing. updateStorage runs the response back through pick(), the same subset filter used when the favorite was created, so the fetch cannot add any field the stored copy lacks. What it can do is refresh values: a ride cancelled or retimed after you favorited it currently gets picked up here. After this change, a favorite would show what it showed when you saved it until you open it.
That looks like the intended design rather than a regression:
pick()'s own comment says "doesn't store newsflash: there's no fast refresh; it might be stale."- The comment at the call site describes a background refresh as future work.
docs/CalVue.mdlists both "a disclaimer about opening each favorite to see the latest information" and "future: server helper to quick update favorite status" as open items.
So the accidental refresh is doing a job nobody has designed yet, in the least efficient shape available — serially, on the critical path, on every visit. If you would rather keep refreshing, the fix is still correct and the refresh wants to become deliberate: batched or parallel rather than one awaited request per favorite.
Impact
Negligible on localhost, but it is a serial chain in front of the render. On a mobile connection at 100–300 ms per round trip, twenty favorites would be several seconds before the view settles. It is also avoidable load on the API box for data the client already has.
Possibly related to the "favorites need pagination" item in docs/CalVue.md — some of what makes that page feel slow may be this rather than the rendering.
- Ngôn ngữ chính
- JavaScript
- Star
- 30
- Fork
- 25
- Merge trung bình
- 9 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của shift-org/shift-docs
-
Unknown --db values report a TypeError instead of the intended errorCó thể đã có người làm @gangster đã nhận 62 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
shift-org/shift-docs#1091 ·
-
validateRideLength accepts any Object.prototype key as a ride lengthCó thể đã có người làm @gangster đã nhận 62 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
shift-org/shift-docs#1089 ·
-
sitemap.xml emits relative <loc> values, so search engines reject itCó thể đã có người làm @dduugg đã nhận 89 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
shift-org/shift-docs#1082 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
shift-org/shift-docs#1072 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
shift-org/shift-docs#1054 ·
Tất cả issue của shift-org/shift-docs
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 3 ngày
-
audit.md numbers Theming and Responsive Design differently in the headings and the score tableCó thể đã có người làm @pbakaus đã nhận hôm nay. Đang mởneeds triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
pbakaus/impeccable#979 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/web interface
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mastodon/mastodon#40924 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fireEvent.select does not wrap its automatic native focus in actCó thể đã có người làm @sergioperezcheco đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
bug user-priority/P2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
Maintainer thường phản hồi trong vòng 1 ngày