Skip to content

Add cached emotes fallback for failed provider fetches - #6125

Merged
pajlada merged 16 commits into
Chatterino:masterfrom
occluder:cache-providers
Apr 12, 2025
Merged

pajlada merged 16 commits into
Chatterino:masterfrom
occluder:cache-providers

Conversation

@occluder

Copy link
Copy Markdown
Contributor

This PR introduces a cached fallback mechanism for emotes when provider API requests fail, lessening the pain of service hiccups

  • Emote loading now starts with cached emotes (if available) to display them immediately
  • An async call is then made to fetch latest data
  • If the call succeeds, the response is used and the cache gets updated
  • If the call fails, the cached version remains loaded, and a system message alerts users about the fallback

Things I'd like to note:

  1. This is only for third-party emote providers, Twitch global/channel emotes aren't considerd
  2. Only the cached emotes are loaded from the stored caches, meaning this currently will not load ffz's custom vip/mod badges or 7tv's emoteSet string even though they are saved

Closes #5676

@jupjohn

jupjohn commented Apr 1, 2025

Copy link
Copy Markdown
Contributor

Haven't looked at the changes (which would answer this,) but would be interested to know if you'd start seeing emotes in messages pulled from recent messages on startup 🤔

@occluder

occluder commented Apr 1, 2025

Copy link
Copy Markdown
Contributor Author

Haven't looked at the changes (which would answer this,) but would be interested to know if you'd start seeing emotes in messages pulled from recent messages on startup 🤔

Isn't this already the case? I'm on latest nightly and I see what you described

@pajlada

pajlada commented Apr 1, 2025

Copy link
Copy Markdown
Member

Thanks for your PR, I'll take a look later this week

@Nerixyz Nerixyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but would be interested to know if you'd start seeing emotes in messages pulled from recent messages on startup

Recent messages and the emote providers are racing. If we load cached emotes, we should be more likely to have loaded emotes when the recent messages response comes back. I couldn't find an issue, but there was some talk about saving the user-id in the window layout such that a channel will know its user-id on startup. This way we could load emotes even earlier, but should delay loading the message history.

Comment thread src/providers/bttv/BttvEmotes.cpp Outdated
Comment thread src/providers/bttv/BttvEmotes.cpp Outdated
Comment thread src/util/Helpers.cpp Outdated
Comment thread src/util/Helpers.cpp Outdated
Comment thread src/util/Helpers.cpp Outdated
Comment thread src/providers/bttv/BttvEmotes.cpp Outdated
Comment thread src/util/Helpers.cpp Outdated
Comment on lines +328 to +338
QThreadPool::globalInstance()->start([bytes, id, provider]() {
QFile responseCache(getApp()->getPaths().cacheDirectory() + "/" + id +
"." + provider);

if (responseCache.open(QIODevice::WriteOnly))
{
qCDebug(chatterinoCache)
<< "Saved json response " << id << "." << provider;
responseCache.write(qCompress(bytes));
}
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is writing to a file really so slow that this needs to be done on a separate thread?

@Wissididom Wissididom Apr 1, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, yes. For example I have an external 10 TB HDD, which if it hasn't been used a while needs time to be responsive again. If the drive, the file is located on, is being used a lot anyways I don't see it as a big problem, tho.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like to mention that some users have a stupid amount of emotes on 7tv, given the generous emote capacity provided

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nymn's 7TV channel emotes, even compressed, is 589KB

some of it has to do with how large the network payload is since we're not only storing raw emote id/url stuff, but still kinda large

@pajlada
pajlada enabled auto-merge (squash) April 12, 2025 10:53
@pajlada
pajlada merged commit 7c8274e into Chatterino:master Apr 12, 2025
@pajlada

pajlada commented Apr 12, 2025

Copy link
Copy Markdown
Member

Thank you! As a first-time contributor, you are now eligible to be listed in the About page in Chatterino.

If you want this, you can open a new PR where you modify the resources/contributors.txt file and add yourself to the list. Read the comments at the top for instructions.

babicekmarek pushed a commit to babicekmarek/streamally-chatterino that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants