Open VyrCossont opened 5 days ago
On further investigation, this looks like CORS preflighting, not API feature detection. However, other web-based Mastodon clients such as the official Mastodon webapp, Semaphore, and Elk don't trigger anywhere near as many CORS preflight requests, and Elk uses the same Mastodon client, so it seems specific to Phanpy.
Same issue on Chrome 126.0.6478.127. It does not appear to happen in Safari 17.5 (19618.2.12.11.6), although Safari's dev tools don't show CORS preflight requests so I had to use Proxyman to check this.
@VyrCossont
Access-Control-Max-Age
will prevent the browser from constantly sending preflight requests.@cheeaun
Access-Control-Max-Age
headers in the responses.It's possible this is down to Phanpy being much more chatty than other clients: I'm seeing a lot of requests for individual accounts and statuses by ID when I scroll the timeline, which all have unique URLs (since the account or status ID is part of the URL path), and thus wouldn't benefit from the ACMA header unless the exact same thing was fetched again. Is there some reason Phanpy is fetching those individually, instead of using the accounts and statuses returned in a given timeline span?
Hmm, possible 🤔. These are the reasons for those individual fetches:
Post fetches:
Account fetches:
inReplyToAccountId
but mentions
is empty, usually when folks reply without putting at-mentions text in the post content.Since the start of development, I've carefully added these features one-by-one as to not accidentally exceed the API rate limit, by observing user feedback. The fetches are also throttled with 1s interval and cached in-memory.
Describe the bug
To Reproduce
OPTIONS
request before almost any other API call HTTP request.Expected behavior Phanpy should not send so many
OPTIONS
requests. This causes unnecessary network traffic and unnecessary work for the server, and might result in Phanpy (and other clients sharing the same IP, including other Phanpy instances) getting rate limited.Screenshots![Firefox dev tools showing about one `OPTIONS` HTTP request before any other HTTP request](https://github.com/cheeaun/phanpy/assets/26195552/78eda45c-286f-4621-a458-ce00f2ea426d)
Desktop:
Additional context I'm guessing this is part of Mastodon API feature detection, but it shouldn't be necessary to preflight literally every API route. Even caching the results for a given API route for a few minutes would help a lot.