Closed ncla closed 10 years ago
I am not too bright sometimes. Same $.each for .items already exists when going through backpack items to fetch market price, just reuse that..
So for only fetching prices for backpacks, I did this. If the Item object already has made some friends, they will have the lowest price appended fast, if the Item doesn't have any friends referenced, it will go looking for some.
Item.prototype.insertMarketValue = function(lowestPrice) {
var self = this;
if(this.myFriends) {
for (var index in self.myFriends) {
var $myLittleItem = $(self.myFriends[index]["item"]);
$myLittleItem.addClass('marketPriced');
$myLittleItem.find(".rarity").html(lowestPrice);
}
}
else {
$(".item").each(function() {
var $theItem = $(this);
if(!$theItem.hasClass('marketPriced')) {
if ($theItem.find("img.smallimg").attr("alt") == self.itemName) {
$theItem.find(".rarity").html(lowestPrice);
$theItem.addClass('marketPriced');
}
}
});
}
};
Seems to be working great.
You also could save a bit by using vanilla JS instead of jQuery, although I doubt it would have any visible impact (unless you're running it on 10k+ elements). See this for speed comparison - roughly 600% speed increase on my laptop.
Yeah, anything Vanilla JS > jQuery in performance, which is good for background tasks.
Not too happy how fast this currently is executing, the performance issue is most noticeable on larger backpacks. Suggestions?