<commit_before>(function() {
  'use strict';

  angular.module('dimApp')
    .factory('dimVendorService', VendorService);

  VendorService.$inject = [
    '$rootScope',
    'dimBungieService',
    'dimStoreService',
    'dimDefinitions',
    'dimFeatureFlags',
    'dimPlatformService',
    '$q'
  ];

  function VendorService(
    $rootScope,
    dimBungieService,
    dimStoreService,
    dimDefinitions,
    dimFeatureFlags,
    dimPlatformService,
    $q
  ) {
    /*
    const allVendors = [
      1990950, // Titan Vanguard
      44395194, // Vehicles
      134701236, // <NAME>
      174528503, // <NAME>
      242140165, // Iron Banner
      459708109, // Shipwright
      570929315, // Gunsmith
      614738178, // Emote Collection
      1303406887, // Cryptarch (Reef)
      1410745145, // Queen's Wrath
      1460182514, // Exotic Weapon Blueprints
      1527174714, // Bounty Tracker
      1575820975, // Warlock Vanguard
      1808244981, // New Monarchy
      1821699360, // Future War Cult
      1889676839, // Disciple of Osiris
      1998812735, // House of Judgment
      2021251983, // Postmaster
      2190824860, // Vanguard Scout
      2190824863, // <NAME> (Cryptarch)
      2244880194, // Ship Collection
      2420628997, // Shader Collection
      2610555297, // Iron Banner
      2648860054, // Iron Lord
      2668878854, // Vanguard Quartermaster
      2680694281, // The Speaker
      2762206170, // Postmaster
      2796397637, // Agent of the Nine
      3003633346, // <NAME>
      3301500998, // Emblem Collection
      3611686524, // Dead Orbit
      3658200622, // Crucible Quartermaster
      3746647075, // Crucible Handler
      3902439767, // Exotic Armor Blueprints
      3917130357, // Eververse
      4269570979 // Cryptarch (Tower)
    ];
     */

    // Vendors we don't want to load by default
    const vendorBlackList = [
      2796397637, // Agent of the Nine
      2021251983, // Postmaster,
      4269570979, // Cryptarch (Tower)
      1303406887 // Cryptarch (Reef)
    ];

    let _reloadPromise = null;

    const service = {
      vendorsLoaded: false,
      reloadVendors: reloadVendors,
      // By hash
      vendors: {},
      totalVendors: 0,
      loadedVendors: 0
      // TODO: expose getVendor promise, idempotently?
    };

    $rootScope.$on('dim-stores-updated', function(e, stores) {
      // TODO: trigger on characters, not stores
      if (stores.stores.length) {
        service.reloadVendors(stores.stores);
      }
    });

    $rootScope.$on('dim-active-platform-updated', function() {
      service.vendors = {};
      service.vendorsLoaded = false;
    });

    return service;


    function reloadVendors(stores) {
      const activePlatform = dimPlatformService.getActive();
      if (_reloadPromise && _reloadPromise.activePlatform === activePlatform) {
        return _reloadPromise;
      }

      const characters = _.reject(stores, 'isVault');

      _reloadPromise = dimDefinitions
        .then((defs) => {
          // Narrow down to only visible vendors (not packages and such)
          const vendorList = _.filter(defs.Vendor, (v) => v.summary.visible);

          service.totalVendors = characters.length * (vendorList.length - vendorBlackList.length);
          service.loadedVendors = 0;

          return $q.all(_.flatten(vendorList.map((vendorDef) => {
            if (vendorBlackList.includes(vendorDef.hash)) {
              return null;
            }

            if (service.vendors[vendorDef.hash] &&
                service.vendors[vendorDef.hash].expires > Date.now()) {
              service.loadedVendors++;
              return service.vendors[vendorDef.hash];
            } else {
              return $q.all(characters.map((store) => loadVendorForCharacter(store, vendorDef, defs)))
                .then((vendors) => {
                  const nonNullVendors = _.compact(vendors);
                  if (nonNullVendors.length) {
                    const mergedVendor = mergeVendors(_.compact(vendors));
                    service.vendors[mergedVendor.hash] = mergedVendor;
                  }
                });
            }
          })));
        })
        .then(() => {
          $rootScope.$broadcast('dim-vendors-updated');
          service.vendorsLoaded = true;
        })
        .finally(function() {
          // Clear the reload promise so this can be called again
          if (_reloadPromise.activePlatform === activePlatform) {
            _reloadPromise = null;
          }
        });

      _reloadPromise.activePlatform = activePlatform;
      return _reloadPromise;
    }

    // TODO: loadVendor (loads appropriate chars)


    function mergeVendors([firstVendor, ...otherVendors]) {
      const mergedVendor = angular.copy(firstVendor);
<commit_msg>Delete vendor if it's no longer available<commit_after>(function() {
  'use strict';

  angular.module('dimApp')
    .factory('dimVendorService', VendorService);

  VendorService.$inject = [
    '$rootScope',
    'dimBungieService',
    'dimStoreService',
    'dimDefinitions',
    'dimFeatureFlags',
    'dimPlatformService',
    '$q'
  ];

  function VendorService(
    $rootScope,
    dimBungieService,
    dimStoreService,
    dimDefinitions,
    dimFeatureFlags,
    dimPlatformService,
    $q
  ) {
    /*
    const allVendors = [
      1990950, // Titan Vanguard
      44395194, // Vehicles
      134701236, // Guardian Outfitter
      174528503, // <NAME>
      242140165, // Iron Banner
      459708109, // Shipwright
      570929315, // Gunsmith
      614738178, // Emote Collection
      1303406887, // Cryptarch (Reef)
      1410745145, // Queen's Wrath
      1460182514, // Exotic Weapon Blueprints
      1527174714, // Bounty Tracker
      1575820975, // Warlock Vanguard
      1808244981, // New Monarchy
      1821699360, // Future War Cult
      1889676839, // Disciple of Osiris
      1998812735, // House of Judgment
      2021251983, // Postmaster
      2190824860, // Vanguard Scout
      2190824863, // <NAME> (Cryptarch)
      2244880194, // Ship Collection
      2420628997, // Shader Collection
      2610555297, // Iron Banner
      2648860054, // Iron Lord
      2668878854, // Vanguard Quartermaster
      2680694281, // The Speaker
      2762206170, // Postmaster
      2796397637, // Agent of the Nine
      3003633346, // Hunter Vanguard
      3301500998, // Emblem Collection
      3611686524, // Dead Orbit
      3658200622, // Crucible Quartermaster
      3746647075, // Crucible Handler
      3902439767, // Exotic Armor Blueprints
      3917130357, // Eververse
      4269570979 // Cryptarch (Tower)
    ];
     */

    // Vendors we don't want to load by default
    const vendorBlackList = [
      2796397637, // Agent of the Nine
      2021251983, // Postmaster,
      4269570979, // Cryptarch (Tower)
      1303406887 // Cryptarch (Reef)
    ];

    let _reloadPromise = null;

    const service = {
      vendorsLoaded: false,
      reloadVendors: reloadVendors,
      // By hash
      vendors: {},
      totalVendors: 0,
      loadedVendors: 0
      // TODO: expose getVendor promise, idempotently?
    };

    $rootScope.$on('dim-stores-updated', function(e, stores) {
      // TODO: trigger on characters, not stores
      if (stores.stores.length) {
        service.reloadVendors(stores.stores);
      }
    });

    $rootScope.$on('dim-active-platform-updated', function() {
      service.vendors = {};
      service.vendorsLoaded = false;
    });

    return service;


    function reloadVendors(stores) {
      const activePlatform = dimPlatformService.getActive();
      if (_reloadPromise && _reloadPromise.activePlatform === activePlatform) {
        return _reloadPromise;
      }

      const characters = _.reject(stores, 'isVault');

      _reloadPromise = dimDefinitions
        .then((defs) => {
          // Narrow down to only visible vendors (not packages and such)
          const vendorList = _.filter(defs.Vendor, (v) => v.summary.visible);

          service.totalVendors = characters.length * (vendorList.length - vendorBlackList.length);
          service.loadedVendors = 0;

          return $q.all(_.flatten(vendorList.map((vendorDef) => {
            if (vendorBlackList.includes(vendorDef.hash)) {
              return null;
            }

            if (service.vendors[vendorDef.hash] &&
                service.vendors[vendorDef.hash].expires > Date.now()) {
              service.loadedVendors++;
              return service.vendors[vendorDef.hash];
            } else {
              return $q.all(characters.map((store) => loadVendorForCharacter(store, vendorDef, defs)))
                .then((vendors) => {
                  const nonNullVendors = _.compact(vendors);
                  if (nonNullVendors.length) {
                    const mergedVendor = mergeVendors(_.compact(vendors));
                    service.vendors[mergedVendor.hash] = mergedVendor;
                  } else {
                    delete service.vendors[vendorDef.hash];
                  }
                });
            }
          })));
        })
        .then(() => {
          $rootScope.$broadcast('dim-vendors-updated');
          service.vendorsLoaded = true;
        })
        .finally(function() {
          // Clear the reload promise so this can be called again
          if (_reloadPromise.activePlatform === activePlatform) {
            _reloadPromise = null;
          }
        });

      _reloadPromise.activePlatform = activePlatform;
      return _reloadPromise;
    }

    // TODO: loadVendor (loads appropriate chars)


    function mergeVendors([firstVendor, ...otherVendors]) {
      const mergedVendor = angular.copy(firstVendor);

{'fraction_non_alphanumeric': 0.10991957104557641, 'fraction_numerical': 0.08084141060012373, 'mean_word_length': 2.0615530303030303, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3010758', 'n_tokens_mistral': 3435, 'n_tokens_neox': 2870, 'n_words': 607}