Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

[RFC] SGv2.1.1 #256

Merged
merged 33 commits into from
Apr 19, 2018
Merged

[RFC] SGv2.1.1 #256

merged 33 commits into from
Apr 19, 2018

Conversation

kyranet
Copy link
Contributor

@kyranet kyranet commented Mar 29, 2018

Description of the PR

This PR ports several refactors from #228 and goes further by fixing several bugs that are caused in other places. The objective of this PR is to backport some bugfixes that need to be merged quickly while improving the interface in general.

The problem with #228 is that its design has not been fully decided, and it's supposed to implement SQL improvements but goes much further than that. However, some bugfixes don't merge due to QueryBuilder and QueryType not being 100% finished nor ready for production.

Probably fixes #247

Changes Proposed in this Pull Request (List new items in CHANGELOG.MD)

Added:

  • Added Util.objectToTuples for object overload -> array overload in Configuration#update.

Changed:

  • [BREAKING] Modified all SettingResolvers to resolve to primitives (string, number, boolean...) or storable data.
  • Added value array overload to Configuration#update.
  • Changed SchemaFolder#getSQL to SchemaFolder#sqlSchema.
  • Changed SchemaPiece#sql's type from [string, string] to string.
  • Changed ScheduledTask's default value for the property data from null to {}, allowing object spread to attach the id of the executed task in Task#run.
  • Improved performance in Configuration#update.
  • Refactored Gateway#getPath to take piece: null as an option for mixed output.
  • Refactored GatewayStorage to not depend on being inherited.
  • Refactored Util.isClass and Util.isObject for a ~5 times performance boost.
  • Refactored Util.makeObject to take an object as third parameter, allowing SettingGateway's internals to append properties without Object.assign.
  • Refactored several utils for memory performance.
  • Refactored typings to have less code duplication.

Removed:

  • Removed Gateway#getEntry (mixed getEntry and insertEntry into Gateway#get), Gateway#createEntry, and Gateway#insertEntry.
  • Removed Gateway#options and Gateway#defaultSchema.
  • Removed Provider's nice option. As it was only used by the JSON provider. Should use a better system instead.

Fixed:

  • Fixed Util.deepClone trying to iterate over WeakMaps and WeakSets.
  • Fixed a critical sync issue where Configuration#_syncStatus resolved too early.
  • Fixed many typings bugs.

Semver Classification

  • This PR only includes documentation or non-code changes.
  • This PR fixes a bug and does not change the (intended) framework interface.
  • This PR adds methods or properties to the framework interface.
  • This PR removes or renames methods or properties in the framework interface.

@kyranet kyranet added Type: Enhancement Issues and PRs related to feature enhancement. Meta: Refactor Issues and PRs related to refactors. Meta: BugFix PRs that fix bugs or issues. Type: Caching Issues and PRs related to caching. Meta: Error Handling Issues and PRs related to error handling. labels Mar 29, 2018
@kyranet kyranet requested a review from bdistin March 29, 2018 18:20
@bdistin bdistin closed this in 842e3d6 Apr 1, 2018
@kyranet kyranet reopened this Apr 1, 2018
Copy link
Contributor

@UnseenFaith UnseenFaith left a comment

Choose a reason for hiding this comment

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

Just skimmed over really fast so might have missed something.

register(name, schema = {}, options = {}) {
register(name, defaultSchema = {}, { download = true, provider = this.client.options.providers.default } = {}) {
if (typeof name !== 'string') throw new TypeError('You must pass a name for your new gateway and it must be a string.');
if (!this.client.methods.util.isObject(defaultSchema)) throw new TypeError('Schema must be a valid object or left undefined for an empty object.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should just require Util here

this.gateways.register('users', undefined, this.options.gateways.users, false);
this.gateways.register('clientStorage', this.gateways.clientStorageSchema, this.options.gateways.clientStorage, false);
this.gateways.register('guilds', this.gateways.guildsSchema, { download: false, ...this.options.gateways.guilds });
this.gateways.register('users', {}, { download: false, ...this.options.gateways.users });
Copy link
Contributor

Choose a reason for hiding this comment

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

Should add a gateways.userSchema option and set it here instead of an empty object, even if the option by default is an empty object, keeps it consistent with the other ones

}
throw new TypeError(`Invalid value. Expected object, string or Array<string>. Got: ${getDeepTypeName(key)}`);
if (typeof options === 'undefined' && guild && guild.constructor.name === 'Object') [guild, options] = [null, guild];
if (guild) guild = this.gateway._resolveGuild(guild);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just be changed to use the internal resolver for Klasa. There's no reason for this method to be duplicated for Settings when it should be relatively the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with this is that at the moment, the Guild's SettingResolver is incredibly slow and requires await (Configuration#update doesn't use async for performance). Plus it takes three arguments and the error message is misleading.

@@ -176,19 +107,8 @@ class Gateway extends GatewayStorage {
*/
async sync(input, download) {
if (typeof input === 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

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

We talked about this in staff chat.

@kyranet kyranet changed the title [WIP] [RFC] SGv2.1.1 [RFC] SGv2.1.1 Apr 17, 2018
@kyranet
Copy link
Contributor Author

kyranet commented Apr 17, 2018

This PR is ready to land and addresses many issues in the current version of SettingGateway. Requesting review from @UnseenFaith and @bdistin.

I'll write the changelog and guides once I come back home.

@bdistin bdistin merged commit f6a089b into master Apr 19, 2018
@bdistin bdistin deleted the SGv2.1.1 branch April 19, 2018 14:24
@kyranet kyranet added the Mod: SettingsGateway Issues and PRs related to SettingsGateway. label Aug 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Meta: BugFix PRs that fix bugs or issues. Meta: Error Handling Issues and PRs related to error handling. Meta: Refactor Issues and PRs related to refactors. Mod: SettingsGateway Issues and PRs related to SettingsGateway. Type: Caching Issues and PRs related to caching. Type: Enhancement Issues and PRs related to feature enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot set property ... of null (SG)
3 participants