Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Users): remove global user cache #8020

Closed
wants to merge 3 commits into from

Conversation

ckohen
Copy link
Member

@ckohen ckohen commented Jun 6, 2022

Please describe the changes this PR makes and why it should be merged:

Warning
This PR has not yet been fully tested, testing is still under way

Most of what this PR achieves and why is outlined perfectly by that issue, differences and other notes here:

  • UserManager extends BaseManager to not have a false cache property, but still retains resolve(Id)
  • Members are the primary source of truth for user data
  • Presences are a potential primary source of truth, but they create members anyways (and if you have the presence intent it seems highly likely you have the members intent as well)
  • There's a lot of places like Invite where we're creating a User instance that can get stale quickly, is this okay? Yes, it is highly likely that the exact same thing was happening before but went unnoticed.
  • client.user has been changed into a getter instead of removing it completely for now

Status and versioning classification:

  • I know how to update typings and have done so, or typings don't need updating
  • This PR changes the library's interface (methods or parameters added)
  • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)

packages/discord.js/src/util/Util.js Outdated Show resolved Hide resolved
packages/discord.js/typings/index.d.ts Outdated Show resolved Hide resolved
kyranet
kyranet previously requested changes Jun 6, 2022
packages/discord.js/typings/index.d.ts Outdated Show resolved Hide resolved
packages/discord.js/src/structures/Webhook.js Outdated Show resolved Hide resolved
packages/discord.js/src/structures/GuildTemplate.js Outdated Show resolved Hide resolved
packages/discord.js/src/structures/GuildMember.js Outdated Show resolved Hide resolved
Copy link
Contributor

@Syjalo Syjalo left a comment

Choose a reason for hiding this comment

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

image
Description of Client#users should be changed

Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
Co-authored-by: Synbulat Biishev <syjalo.dev@gmail.com>
Co-authored-by: A. Román <kyradiscord@gmail.com>
@iCrawl iCrawl requested review from kyranet and vladfrangu June 7, 2022 10:03
@iCrawl iCrawl dismissed stale reviews from kyranet and vladfrangu June 7, 2022 10:03

Stale

if (user instanceof GuildMember || user instanceof ThreadMember) return user.user;
if (user instanceof Message) return user.author;
return super.resolve(user);
if (user instanceof User) return User;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (user instanceof User) return User;
if (user instanceof User) return user;

@@ -63,7 +64,7 @@ class GuildMember extends Base {
* The user that this guild member instance represents
* @type {?User}
Copy link
Member

Choose a reason for hiding this comment

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

When will this be nullable? Even if data.user would be undefined it will still have an (albeit invalid) user class

Copy link
Member Author

Choose a reason for hiding this comment

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

it won't set the prop if data.user is undefined, there's a lot of places where we use ?Type to indicate undefined instead of explicitly making it null still.

* The owner of the webhook
* @type {?(User|APIUser)}
*/
this.owner = this.owner ? { ...this.owner, ...data.user } : data.user;
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we technically always create a user class? (we'd probably need to have a fake users manager on the webhook client I suppose..) Is that even worth it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't be a fake manager, but also can't be a real one without a some rework, i.e. for createDM, deleteDM

? guild.client.users._add({ id: data.user_id })
: guild.client.users.cache.get(data.user_id)
? guild.client.users._obtain({ id: data.user_id }, guild)
: logs.users.get(data.user_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

What’s logs meant to be? I don’t see it declared anywhere

Copy link
Member

Choose a reason for hiding this comment

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

Its the first parameter in the constructor

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see
But then what’s the type? Is users.get a function?

Copy link
Contributor

@Syjalo Syjalo Jun 8, 2022

Choose a reason for hiding this comment

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

const entry = new GuildAuditLogsEntry(this, guild, item);

private constructor(logs: GuildAuditLogs, guild: Guild, data: RawGuildAuditLogEntryData);

@GravIos3

This comment was marked as spam.

@ckohen
Copy link
Member Author

ckohen commented Jun 25, 2022

After internal discussions, we are going to postpone this to the typescript rewrite after all since it will afford us a lot more flexibility in the implementation,

@ckohen ckohen closed this Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Roadmap: global user cache removal
9 participants