#fetch() vs cache.get() war
1 messages ¡ Page 1 of 1 (latest)
Good idea
@vagrant viper
Channels and guilds are always cached.
Presence only cached when intent is enabled + user has any presence
member only cached when fetched once, retrieve through a member related event, or the first couple hundred members on guild create event(which includes ready event)
emojis are always cached
Voice states are always cached
Users are only cached when the member is cached, or the user dmed the bot
Why fetch when theyâre cached
What
If you have an actual pro which makes logical sense then please share
Cause if they're not cached, you get an extra check on if that user exists?
or channel
They are cached
You're assuming that the cache is never wrong then
Do you mess with sweepers or you donât have the guilds intent?
I think the simple reason I use fetch is for 2 reasons:
1)
Despite what you say about it "already being cached", it gives me a sense of certainty that in a 1 in a million edge-case, I'll still have a result at the end.
I am fully comfortable with Promises, and have no problem dealing with them, and anyone scared of Promises needs to get a grip
It isnât if you have the Guilds intent
To clarify point 1, it might be irrational, but it's how I feel
If a user exists (in general)
You cant outreach an fetch.
If the user id available from the bot (sharing dms/guildâŹ) then after the first fetch it will get cached.
I get that .fetch() would use up rate-limits. But for smaller apps isn't that okay?
I understand, youâre much more proficient in js however
For smaller apps its fine
It doesn't use any rate limits if they're cached, so it's not actually an issue.
fetch when cached = cache.get + promise
But it adds a fetch part to it which you basically donât need
cache.get â promise
Youâre just removing that element
A cache is a store.
With the cache u store what the api returned to u somewhen in the past.
If u can get it out of the store, get it out of there. Why do a fetch if its in there...
Thats what they are saying.
It would be marginally faster
Someone wanna contribute to my advanced logger with over 300 events
I donât see any logical reason to fetch over getting it from the cache, only personal preference
Send it my way đđ
By creating discord issues
But if speed isn't the problem, but data-consistency?
Channels are
ALWAYS
cached
Unless you have sweepers, or you donât have the guilds intent
Sweepers pointing to the channel managers
Channels are always in the cache.
If ur bot has somehow access to them (beeing in the guild of the channel)
Even the channels the bot cant see aka doesnt have perms for view channel
It's just a marginal data consistency
if you look in the RAW EVENT
Youll see that once the bot gets ready it retrieves for all guilds data, which includes for every guild presences, parts of the members, channels, emojis and voicestates as well as guild data like guild owner id guild name etc.
If you have a lot of time,
Then, take your time, fetch your stuff,
If you want to be quicker, use cache
That's all
Here we go, the inner-working of GuildMemberManager:
async _fetchSingle({ user, cache, force = false }) {
if (!force) {
const existing = this.cache.get(user);
if (existing && !existing.partial) return existing;
}
const data = await this.client.rest.get(Routes.guildMember(this.guild.id, user));
return this._add(data, cache);
}
Literally, if they exist in the cache, it returns them, so a fetch for a cached entry, is a cache.get + promise, like I said @mild tundra
So in turn keeping the promise part of that function, correct?
Whereas cache.get() is not a promise
handling promises shouldnt be a problem since 2015
and what's wrong with a promise?
Adds time probably
Idk if it doesnât then go for it
But imo if itâs there use it
Yea, this is true, but do you need to worry about that?
Not really
You only need to worry for BIG bots
Just couple ns
If those .xxx ms matters to you, then you're big
For me they do
I donât particularly no, but if itâs there I suggest that you should recommend to use it rather then fetching
my bot responds in 6ms for any discord action, my ws ping is 5-8ms on avg
So if i need to wait 10ms until something happens it feels mega slow
Not really 
But if i need to wait 0.001ms its super faster
I just feel if itâs there and reliable use it
The channel cache is super reliable unless you mess with anything
But if you're working around a database, so everything is already async - it doesn't really break anything adding another await
0.004ms
My db answers within 0.4 and 0.8ms
And i cache it which makes it answer in couple ns again
but still async? @vagrant viper
For get requests
Yes
a promise doesnt mean slow
It just means slower than no promise
Cause nodejs needs to create and close the promise
100% agree
I donât see a logical reason to do it unless itâs not cached đ¤ˇđťââď¸
Something like navijs is faster in promises than nodejs
So 100th of a second, or 7,000ths of a second
So yea, so small
Yea i do the same, but for simplicity its jot worth it
Itâs very small yh but I just find it unnecessary
"irrational feeling" - you're utterly right
But we're still arguing .fetch vs .cache.get
No need to hate on people using it than, or guide them into not using it.
Not hating anyone for using it
The only harm in using fetch, is time
Never did i state that it is better, Iâm saying that I donât think people in this server should recommend it due to most people having problems with promises
What's the problem with promises though?
Oh yea â ď¸
50% of the people in #djs-help-v14 #archive-djs-help-v13 donât know anything about them?
Hmm â ď¸
50% is VERY generous
80%
If you have a problem with promises, you should leave the Server, simple as that. (not you specfically)
Damn â ď¸
đ¤Ł, I mean we are here to teach as well, in some ways
DJS is littered with promises, you should not be here until you understand their basics
ala #rules 2
Mostly @mild tundra been pointing out how shit I am to remembering to do stuff async. That's a huge help
(really đ )
I donât think promises are basic basic thoigh
I find async await better than the .then notation
If you want to use DJS, they are
If you were to use no promises, then you can't use DJS
Iâm talking javascript
Not knowing Promises for DJS, but knowing JS, is like knowing how a Car works, but not how to Drive
Thatâs not what Iâm saying, I said I donât feel promises are something very very basic within the js scope
new Map().get()
Faster than
const map= new Map()
return new Promise(r =>{
r(map.get())})
Thats what they say
I did that earlier, 1.5x slower
So 5 of them in one scope would be 7.5 times slower, no?
And nobody said .fetch() was faster. It was about making sure you have new information before doing an action.
Indeed
No...it's individual
Each request would be 1.5x slower, so the 5 promises would take 1.5x the time as 5 gets
Yh 7.5x slower because thereâs 5 of them
No, that's not how math works
If each 5 awaitâs take 1.5x longer then theyâll stack
1 x 5 = 5
1.5 = 5 = 7.5
5 / 7.5 = 0.6
each takes 1.5 longer, so the total is 1.5x slower still
Specific example here @mild tundra - I'm checking if a channel exisits, and it's specific permissionOverwrites.
If it returns a cache miss ( for any reason, I've had it happen in v13, Don't know if it discord was unstable - or it was a cache problem. I had a death loop of creating channels.
(yes, bad code that allows that) But I'm just saying - a cache miss could be a realy bad thing for some people.
Channels are always cached 
I donât think you understand me but as I said it donât matter anymore as we have established things here
I don't think you understand
He was talking about the total time 
Each being 1.5x slower, doesn't make the whole thing 7.5x slower

The total time isn't 7.5x slower though
It's still 1.5x

If you do 1 request, and 5 requests, the 5 take 5x longer
But doing 5 that take 1s, and 5 that take 2s, doesn't make the latter 10x slower
Ok
they are 2x slower
I know, he probably wanted to say 7.5 and not 7.5x



I will force feed you all an English and Math book đ¤Ł
Not really
Let's agree to disagree 
You just said that if you do one promise action it takes 1.5x longer right
So compare 2 cache.gets to 2 promise actions one after the other theyâll stack
Sometimes you need to feel what another wants to say
Everyone is not a robot â ď¸
They stack, but it doesn't multiple the total time
Simplify it...
Let's say 1x and 2x
1x: 1, 2
2x: 1, 2, 3, 4
For 2 requests
Look weâll agree to disagree lol, youâve already insulted my maths skills
4 is double 2
Let's go with 5 requests
1x: 1, 2, 3, 4, 5
2x:
A, A, B, B, C, C, D, D, E, E
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Also 2x as long
They queue, they don't multiple the resulting time
Just realised an advantage of fetch, it will throw an error if you try and use it when the bot is not ready or Id is wrong, and you'll just get "cannot x of undefined" or the like with a get.