Repository: discordjs/discord.js
File: packages/discord.js/src/managers/EntitlementManager.js (JavaScript)

Code before:
   */

  /**
   * Options used to fetch entitlements
   * @typedef {Object} FetchEntitlementsOptions
   * @property {number} [limit] The maximum number of entitlements to fetch
   * @property {GuildResolvable} [guild] The guild to fetch entitlements for
   * @property {UserResolvable} [user] The user to fetch entitlements for
   * @property {SKUResolvable[]} [skus] The SKUs to fetch entitlements for
   * @property {boolean} [excludeEnded] Whether to exclude ended entitlements
   * @property {boolean} [excludeDeleted] Whether to exclude deleted entitlements
   * @property {boolean} [cache=true] Whether to cache the fetched entitlements
   * @property {Snowflake} [before] Consider only entitlements before this entitlement id
   * @property {Snowflake} [after] Consider only entitlements after this entitlement id
   * <warn>If both `before` and `after` are provided, only `before` is respected</warn>
   */

  /**
   * Fetches entitlements for this application
   * @param {EntitlementResolvable|FetchEntitlementOptions|FetchEntitlementsOptions} [options]
   * Options for fetching the entitlements
   * @returns {Promise<Collection<Snowflake, Entitlement>>}
   */
  async fetch(options) {
    if (!options) return this._fetchMany(options);
    const { entitlement, cache, force } = options;
    const resolvedEntitlement = this.resolveId(entitlement ?? options);

    if (resolvedEntitlement) {
      return this._fetchSingle({ entitlement: resolvedEntitlement, cache, force });
    }

    return this._fetchMany(options);
  }

  async _fetchSingle({ entitlement, cache, force = false }) {
    if (!force) {
      const existing = this.cache.get(entitlement);

      if (existing) {
        return existing;
      }
    }

    const data = await this.client.rest.get(Routes.entitlement(this.client.application.id, entitlement));
    return this._add(data, cache);
  }

  async _fetchMany({ limit, guild, user, skus, excludeEnded, excludeDelete, cache, before, after } = {}) {
    const query = makeURLSearchParams({
      limit,

Review comment (performance):
```suggestion
    const { entitlement, cache = true, force } = options;
```

Code after:
   */

  /**
   * Options used to fetch entitlements
   * @typedef {Object} FetchEntitlementsOptions
   * @property {number} [limit] The maximum number of entitlements to fetch
   * @property {GuildResolvable} [guild] The guild to fetch entitlements for
   * @property {UserResolvable} [user] The user to fetch entitlements for
   * @property {SKUResolvable[]} [skus] The SKUs to fetch entitlements for
   * @property {boolean} [excludeEnded] Whether to exclude ended entitlements
   * @property {boolean} [excludeDeleted] Whether to exclude deleted entitlements
   * @property {boolean} [cache=true] Whether to cache the fetched entitlements
   * @property {Snowflake} [before] Consider only entitlements before this entitlement id
   * @property {Snowflake} [after] Consider only entitlements after this entitlement id
   * <warn>If both `before` and `after` are provided, only `before` is respected</warn>
   */

  /**
   * Fetches entitlements for this application
   * @param {EntitlementResolvable|FetchEntitlementOptions|FetchEntitlementsOptions} [options]
   * Options for fetching the entitlements
   * @returns {Promise<Entitlement|Collection<Snowflake, Entitlement>>}
   */
  async fetch(options) {
    if (!options) return this._fetchMany(options);
    const { entitlement, cache, force } = options;
    const resolvedEntitlement = this.resolveId(entitlement ?? options);

    if (resolvedEntitlement) {
      return this._fetchSingle({ entitlement: resolvedEntitlement, cache, force });
    }

    return this._fetchMany(options);
  }

  async _fetchSingle({ entitlement, cache, force = false }) {
    if (!force) {
      const existing = this.cache.get(entitlement);

      if (existing) {
        return existing;
      }
    }

    const data = await this.client.rest.get(Routes.entitlement(this.client.application.id, entitlement));
    return this._add(data, cache);
  }

  async _fetchMany({ limit, guild, user, skus, excludeEnded, excludeDeleted, cache, before, after } = {}) {
    const query = makeURLSearchParams({
      limit,