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

feat: remove datastores and implement Managers #3696

Merged
merged 43 commits into from
Feb 11, 2020

Conversation

RDambrosio016
Copy link
Contributor

@RDambrosio016 RDambrosio016 commented Jan 15, 2020

Please describe the changes this PR makes and why it should be merged:
This PR completely removes DataStores, and it implements Managers. The reasons for this change are highlighted in #3485, and this pr mostly implements it.

Testing

Due to the inherent breaking nature of this PR, it is not completely testable by one person. if you would like to aid in testing this pr, simply install the branch with:
npm i git://github.com/RDambrosio016/discord.js.git#remove-datastores. If you encounter any weird behavior or errors, please either comment below, or ping me on the discord server (@BorgerKing#1856).

The main focus of the PR is completely separating API and cache for data models.

This allows us to:

  • Easily swap out API methods.
  • Easily extend Managers.
  • Easily swap out cache types.
  • Separate API and cache methods so as not to have weird overwrites on various managers.

Future plans

This pr easily allows us to give users control over caching strategies through dependency injection. Users will extend collection and provide it to a helper class similar to Structures which the managers will use to get the right collection. In addition to this, bans will be made into their own manager, this will centralize the methods so as not to have them in various managers and structures.

Misc changes

  • Managers of any kind are no longer iterable.
  • Managers do not have a Symbol.species of Collection anymore.
  • The BaseManager class is abstract unlike DataStore.
  • Neither the BaseManager class, nor standalone managers extend Collection.
  • Collection methods are no longer overwritten with API methods due to the separation of purposes.
  • Multiple properties on stores have been documented in managers, e.g. MessageManager#channel.
  • MessageStore#remove() has been renamed to MessageManager#delete()

Managers!

Abstract:

DataStore => BaseManager

Extends BaseManager:

GuildChannelStore => GuildChannelManager
GuildEmojiStore => GuildEmojiManager
GuildMemberStore => GuildMemberManager
MessageStore => MessageManager
PresenceStore => PresenceManager
ReactionStore => ReactionManager
GuildStore => GuildManager
ReactionUserStore => ReactionUserManager
UserStore => UserManager
RoleStore => RoleManager

Standalone (cache is a getter):

GuildMemberRoleStore => GuildMemberRoleManager
GuildEmojiRoleStore => GuildEmojiRoleManager

todo

  • Rethink if Standalone stores should/could be reworked to extend BaseManager.
  • Check over typings to see if they are fully correct.
  • Overall testing.
  • Test if docs work fine.
  • Change jsdoc to remove references to stores/ use managers properly

Status

  • Code changes have been partially tested against the Discord API.
  • I know how to update typings and have done so.

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

This PR includes significant breaking changes to both how users interact with cache, and how internals interact with the cache. It also renames some methods such as MessageStore#remove().

Copy link
Member

@appellation appellation left a comment

Choose a reason for hiding this comment

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

Initial, obvious typos/nits

Copy link
Member

@amishshah amishshah left a comment

Choose a reason for hiding this comment

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

Really great PR! It achieves the points set out in #3485. Most of my complaints are just nitpicks over documentation conventions, I found very few logical errors 😄 🎉

  • Some inconsistencies with capitalisation of data structures
  • Some descriptions include "the cache of this Manager" whereas others include the specific structure, e.g. "the role cache of this Manager"

@RDambrosio016 RDambrosio016 marked this pull request as ready for review January 17, 2020 00:41
Copy link
Member

@amishshah amishshah left a comment

Choose a reason for hiding this comment

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

Just some minor corrections I have for the docs

Copy link
Contributor

@Jyguy Jyguy left a comment

Choose a reason for hiding this comment

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

message.reactions.clear(); of line 16 in src/client/actions/MessageReactionRemoveAll.js should be message.reactions.cache.clear();

@iCrawl iCrawl changed the title Remove datastores and implement Managers feat: remove datastores and implement Managers Feb 11, 2020
@iCrawl iCrawl merged commit bbdbc4c into discordjs:master Feb 11, 2020
Gr8z added a commit to botbind/discord.js that referenced this pull request Feb 12, 2020
@RDambrosio016 RDambrosio016 deleted the remove-datastores branch February 12, 2020 17:38
samsamson33 pushed a commit to samsamson33/discord.js that referenced this pull request Feb 27, 2020
* Initial commit: add 5 initial managers

- Base manager
- GuildChannelManager
- MessageManager
- PresenceManager
- Reaction Manager
- Added LimitedCollection

* Add GuildEmojiManager, various fixes

* Modify some managers and add guildmembermanager

* Initial integration

* Delete old stores

* Integration part two, removed LRUCollection

- Most of the integration has been finished
- TODO typings
- Removed LRUCollection, needless sweeping

* Typings + stuff i somehow missed in ChannelManager

* LimitedCollection typings/ final changes

* Various jsdoc and syntactical fixes, Removed Util.mixin()

* tslint fix

* Grammatical and logical changes

* Delete temporary file placed by mistake

* Grammatical changes

* Add missing type

* Update jsdoc examples

* fix: ChannelManager#remove should call cache#delete not cache#remove

* fix recursive require

* Fix missed cache in util

* fix: more missed cache

* Remove accidental _fetchMany change from discordjs#3645

* fix: use .cache.delete() over .remove()

* fix: missing cache in ReactionCollector

* fix: missed cache in client

* fix: members is a collection not a manager

Co-Authored-By: Sugden <[email protected]>

* fix: various docs and cache fixes

* fix: missed cache

* fix: missing _roles

* Final testing and debugging

* LimitedCollection: return the Collection instead of undefined on .set

* Add cache to BaseManager in typings

* Commit fixes i forgot to stage yesterday

* Update invite events

* Account for new commit

* fix: MessageReactionRemoveAll should call .cache.clear()

* fix: add .cache at various places, correct return type

* docs: remove mentions of 'store'

* Add extra documented properties to typings

Co-authored-by: Sugden <[email protected]>
Co-authored-by: SpaceEEC <[email protected]>
samsamson33 added a commit to samsamson33/discord.js that referenced this pull request Feb 27, 2020
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.

8 participants