mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-09-16 01:56:55 +00:00
Improve cache
Also implement cache for emote sets added by FFZ
This commit is contained in:
parent
d384263f9f
commit
37c042518e
1 changed files with 136 additions and 51 deletions
|
@ -129,6 +129,12 @@ export default class Input extends Module {
|
||||||
ANELE: 14648986,
|
ANELE: 14648986,
|
||||||
PJSalt: 14438861
|
PJSalt: 14438861
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.tabCompleteHydrationCache = [];
|
||||||
|
this.tabCompleteHydrationCacheLength = -1;
|
||||||
|
|
||||||
|
this.tabCompleteFFZHydrationCache = [];
|
||||||
|
this.tabCompleteFFZHydrationCacheLength = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
async onEnable() {
|
async onEnable() {
|
||||||
|
@ -224,6 +230,14 @@ export default class Input extends Module {
|
||||||
this.MentionSuggestions.on('mount', this.overrideMentionMatcher, this);
|
this.MentionSuggestions.on('mount', this.overrideMentionMatcher, this);
|
||||||
|
|
||||||
this.on('site.css_tweaks:update-chat-css', this.resizeInput, this);
|
this.on('site.css_tweaks:update-chat-css', this.resizeInput, this);
|
||||||
|
this.on('chat.emotes:change-hidden', () => {
|
||||||
|
this.tabCompleteHydrationCacheLength = -1;
|
||||||
|
this.tabCompleteFFZHydrationCacheLength = -1;
|
||||||
|
}, this);
|
||||||
|
this.on('site.chat.emote_menu:change-hidden-set', () => {
|
||||||
|
this.tabCompleteHydrationCacheLength = -1;
|
||||||
|
this.tabCompleteFFZHydrationCacheLength = -1;
|
||||||
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateInput() {
|
updateInput() {
|
||||||
|
@ -470,33 +484,67 @@ export default class Input extends Module {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getHydratedEmoteSets(inst) {
|
||||||
|
if(this.tabCompleteHydrationCacheLength !== inst.props.emotes.length) {
|
||||||
|
this.tabCompleteHydrationCache = [];
|
||||||
|
|
||||||
|
const hidden = this.emotes.getHidden('twitch');
|
||||||
|
|
||||||
|
const hydratedEmoteSets = inst.hydrateEmotes(inst.props.emotes);
|
||||||
|
|
||||||
|
if (Array.isArray(hydratedEmoteSets)) {
|
||||||
|
const filteredEmoteSets = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < hydratedEmoteSets.length; i++) {
|
||||||
|
const set = hydratedEmoteSets[i];
|
||||||
|
|
||||||
|
const filteredSet = { ...set, emotes: [] };
|
||||||
|
|
||||||
|
const owner = inst.props.emotes[i].owner;
|
||||||
|
if (owner && this.emotes.isSetHidden('twitch', owner.id)) {
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// // In case we do still need the owner information
|
||||||
|
// filteredSet.owner = owner;
|
||||||
|
|
||||||
|
// if (this.emotes.isSetHidden('twitch', owner.id)) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < set.emotes.length; i++) {
|
||||||
|
const emote = set.emotes[i];
|
||||||
|
|
||||||
|
if (!hidden.includes(emote.id)) {
|
||||||
|
filteredSet.emotes.push(emote);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredEmoteSets.push(filteredSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tabCompleteHydrationCache = filteredEmoteSets;
|
||||||
|
this.tabCompleteHydrationCacheLength = inst.props.emotes.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.tabCompleteHydrationCache;
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line class-methods-use-this
|
// eslint-disable-next-line class-methods-use-this
|
||||||
getTwitchEmoteSuggestions(input, inst) {
|
getTwitchEmoteSuggestions(input, inst) {
|
||||||
const hydratedEmotes = inst.hydrateEmotes(inst.props.emotes);
|
const hydratedEmoteSets = this.getHydratedEmoteSets(inst);
|
||||||
if (!Array.isArray(hydratedEmotes)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < hydratedEmotes.length; i++) {
|
|
||||||
const owner = inst.props.emotes[i].owner;
|
|
||||||
if (owner) {
|
|
||||||
hydratedEmotes[i].owner = owner;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const usageResults = [],
|
const usageResults = [],
|
||||||
startingResults = [],
|
startingResults = [],
|
||||||
otherResults = [],
|
otherResults = [],
|
||||||
favorites = this.emotes.getFavorites('twitch'),
|
favorites = this.emotes.getFavorites('twitch'),
|
||||||
hidden = this.emotes.getHidden('twitch'),
|
|
||||||
search = input.startsWith(':') ? input.slice(1) : input;
|
search = input.startsWith(':') ? input.slice(1) : input;
|
||||||
|
|
||||||
for (const set of hydratedEmotes) {
|
for (const set of hydratedEmoteSets) {
|
||||||
if (set && Array.isArray(set.emotes)) {
|
if (set && Array.isArray(set.emotes)) {
|
||||||
if ( ! this.emotes.isSetHidden('twitch', set.owner?.id)) {
|
|
||||||
for (const emote of set.emotes) {
|
for (const emote of set.emotes) {
|
||||||
if (inst.doesEmoteMatchTerm(emote, search) && ! hidden.includes(emote.id)) {
|
if (inst.doesEmoteMatchTerm(emote, search)) {
|
||||||
const favorite = favorites.includes(emote.id);
|
const favorite = favorites.includes(emote.id);
|
||||||
const element = {
|
const element = {
|
||||||
current: input,
|
current: input,
|
||||||
|
@ -521,7 +569,6 @@ export default class Input extends Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
usageResults.sort((a, b) => this.EmoteUsageCount[b.replacement] - this.EmoteUsageCount[a.replacement]);
|
usageResults.sort((a, b) => this.EmoteUsageCount[b.replacement] - this.EmoteUsageCount[a.replacement]);
|
||||||
startingResults.sort((a, b) => a.replacement.localeCompare(b.replacement));
|
startingResults.sort((a, b) => a.replacement.localeCompare(b.replacement));
|
||||||
|
@ -572,6 +619,45 @@ export default class Input extends Module {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFFZEmoteSuggestionsCache(user_id, user_login, room_id, room_login) {
|
||||||
|
const sets = this.emotes.getSets(
|
||||||
|
user_id,
|
||||||
|
user_login,
|
||||||
|
room_id,
|
||||||
|
room_login
|
||||||
|
);
|
||||||
|
|
||||||
|
if(this.tabCompleteFFZHydrationCacheLength !== sets.length) {
|
||||||
|
this.tabCompleteFFZHydrationCache = [];
|
||||||
|
|
||||||
|
if (Array.isArray(sets)) {
|
||||||
|
const filteredEmoteSets = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < sets.length; i++) {
|
||||||
|
const set = sets[i];
|
||||||
|
|
||||||
|
if (this.emotes.isSetHidden(set.source || 'ffz', set.id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filteredSet = { ...set, emotes: [] };
|
||||||
|
|
||||||
|
for(const emote of Object.values(set.emotes)) {
|
||||||
|
if (!this.emotes.isHidden(set.source || 'ffz', emote.id)) {
|
||||||
|
filteredSet.emotes.push(emote);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredEmoteSets.push(filteredSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tabCompleteFFZHydrationCache = filteredEmoteSets;
|
||||||
|
this.tabCompleteFFZHydrationCacheLength = sets.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.tabCompleteFFZHydrationCache;
|
||||||
|
}
|
||||||
|
|
||||||
getEmoteSuggestions(input, inst) {
|
getEmoteSuggestions(input, inst) {
|
||||||
const user = inst._ffz_user,
|
const user = inst._ffz_user,
|
||||||
|
@ -589,7 +675,7 @@ export default class Input extends Module {
|
||||||
|
|
||||||
const search = input.startsWith(':') ? input.slice(1) : input,
|
const search = input.startsWith(':') ? input.slice(1) : input,
|
||||||
results = [],
|
results = [],
|
||||||
sets = this.emotes.getSets(
|
sets = this.getFFZEmoteSuggestionsCache(
|
||||||
user && user.id,
|
user && user.id,
|
||||||
user && user.login,
|
user && user.login,
|
||||||
channel_id,
|
channel_id,
|
||||||
|
@ -599,9 +685,8 @@ export default class Input extends Module {
|
||||||
|
|
||||||
for(const set of sets) {
|
for(const set of sets) {
|
||||||
if ( set && set.emotes )
|
if ( set && set.emotes )
|
||||||
if ( ! this.emotes.isSetHidden(set.source || 'ffz', set.id))
|
|
||||||
for(const emote of Object.values(set.emotes))
|
for(const emote of Object.values(set.emotes))
|
||||||
if ( inst.doesEmoteMatchTerm(emote, search) && !added_emotes.has(emote.name) && ! this.emotes.isHidden(set.source || 'ffz', emote.id) ) {
|
if (inst.doesEmoteMatchTerm(emote, search) && !added_emotes.has(emote.name)) {
|
||||||
const favorite = this.emotes.isFavorite(set.source || 'ffz', emote.id);
|
const favorite = this.emotes.isFavorite(set.source || 'ffz', emote.id);
|
||||||
results.push({
|
results.push({
|
||||||
current: input,
|
current: input,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue