Skip to content

Weapon ranking service abstraction#1620

Merged
bhollis merged 183 commits intoDestinyItemManager:devfrom
48klocs:WeaponRankingServiceAbstraction
May 9, 2017
Merged

Weapon ranking service abstraction#1620
bhollis merged 183 commits intoDestinyItemManager:devfrom
48klocs:WeaponRankingServiceAbstraction

Conversation

@48klocs
Copy link
Copy Markdown
Contributor

@48klocs 48klocs commented Apr 25, 2017

There were some pain points in the calling to DTR - it was being chattier than it needed to be (knowing that even if you submit data, it's 10 minutes before it'll be reflected) and the way it was laid out, community scores were flickering when the item stores got repainted. I've been informed that could drive lesser folks a little batty!

Also, if you didn't submit your review data and a store refresh happened in the background, that would be lost. Even if you did submit it, it would appear lost for 5-10 minutes because of the lag. These are things that could lead to unhappy support tickets.

So I built out a persistence class. When blur events are caught, user review data's updated (so it's kept around). And community scores are attached there. And community reviews are kept there as well, so if you open and re-open the same item, we won't hammer DTR with requests for data we already have.

There's cache invalidation in it which means I've almost certainly done something wrong.

Theoretically, the stores have actual items in them.
This isn't Hungarian notation, honest.
Dumping cruft and successfully calling.
Copy link
Copy Markdown
Contributor

@bhollis bhollis left a comment

Choose a reason for hiding this comment

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

Nice, getting better. I have a few more comments.

/**
* Fetch the DTR community scores for all weapon items found in the supplied stores.
*
* @param {any} storesContainer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't really help me. It doesn't say anything about what storesContainer is or what properties it might have.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can tell you what it walks and quacks like (an object that contains a property named stores that has all of the stores in it) but I can't tell you what the type is.

I don't know if it's an odd byproduct of how objects get passed from promise to promise or what.

var self = this;
var allDtrItems = _.map(allItems, function(item) { return self._itemTransformer.translateToDtrWeapon(item); });
var allKnownDtrItems = scoreMaintainer.getItemStores();
var allDtrItems = allItems.map(function(item) { return self._itemTransformer.translateToDtrWeapon(item); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Arrow functions allow you to avoid self.

var unmatched = allDtrItems.filter(function(dtrItem) {
var matchingItem = _.findWhere(allKnownDtrItems, { referenceId: String(dtrItem.referenceId), roll: dtrItem.roll });
return (matchingItem === null);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const unmatched = _.reject(allDtrItems, (dtrItem) => _.any(allKnownDtrItems, { referenceId: String(dtrItem.referenceId), roll: dtrItem.roll }));

*
* @param {any} stores
* @param {ReviewDataCache} reviewDataCache
* @returns {array}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stuff like @returns {array} doesn't offer much value as documentation.

dtrWeapons.forEach(function(dtrWeapon) {
if (!self._isKnownWeapon(list, dtrWeapon)) {
list.push(dtrWeapon);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const list = new Set(dtrWeapons);
return Array.from(list); // or leave it as a Set, it'll iterate fine


dtrItem.referenceId = String(dtrItem.referenceId);

return _.findWhere(this._itemStores, { referenceId: dtrItem.referenceId, roll: dtrItem.roll });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should make this a map (object) lookup instead of a linear scan.

}

return matchingItem;
return (this._getMatchingItem(item) || null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unnecessary parentheses.

* Do we have any locally-cached review data for the given item from the DIM store?
*
* @param {any} item
* @returns {any}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Useless docs. The description suggests it'll return a boolean, but it looks like it returns an item (or null). @returns and @param aren't helping at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I saw the note on getMatchingItem() - it's not in translateToDtrWeapon because their API calls for reference IDs to be ints, it's just returning a string in some cases (which I've let them know about).

var tenMinutes = 1000 * 60 * 10;
var self = this;

setTimeout(function() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comments about the task for purging the cache. This should be on the retrieval side, not a setTimeout.

Comment thread src/scripts/feature-flags.js Outdated
debugMoves: false,
// show changelog toaster
changelogToaster: $DIM_FLAVOR === 'release' || $DIM_FLAVOR === 'beta',
sendingWeaponDataEnabled: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be either false or $DIM_FLAVOR === 'dev'.

@bhollis
Copy link
Copy Markdown
Contributor

bhollis commented May 9, 2017

Cool. I think there's more work to do, but this is something we can merge and iterate on in the dev branch.

@bhollis bhollis merged commit 54745fa into DestinyItemManager:dev May 9, 2017
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.

3 participants