Skip to content
This repository has been archived by the owner on Dec 3, 2017. It is now read-only.

Commit

Permalink
Avoid duplicate portals while loading.
Browse files Browse the repository at this point in the history
If multiple updates are interleaved, this.feed_html can be left with
duplicate entries.  Instead of building this.feed_html up bit by bit,
use the `portals` array to build it all at once.
  • Loading branch information
ianh committed Oct 17, 2017
1 parent f0a7a6f commit 6f35221
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions scripts/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function Feed(feed_urls)
online_ports_count += 1;
entries = entries.concat(feed_entries);
this.debounced_sort_refresh(entries);
r.portal.port_list_el.innerHTML = this.feed_html;
r.portal.port_list_el.innerHTML = this.get_feed_html();
})
.catch((e) => {
console.warn(e);
Expand All @@ -58,26 +58,32 @@ function Feed(feed_urls)
});
}

this.get_feed = function(archive)
this.get_feed_html = function()
{
this.feed_html = "";
var feed_html = "";
for(name in r.feed.portals){
console.log(name);
var portal = r.feed.portals[name];
var last_entry = portal.feed[portal.feed.length-1];
var is_active = Math.floor((new Date() - last_entry.timestamp) / 1000);
var rune = portal.port.indexOf(r.portal.data.dat) > -1 ? "@" : "~";

if(is_active > 190000 && portal.name != r.portal.data.name){
feed_html += "<ln title='"+(timeSince(last_entry.timestamp))+"' class='dead' data-operation='un"+portal.dat+"'>"+rune+""+portal.name+"</ln>";
}
else{
feed_html+= "<ln title='"+(timeSince(last_entry.timestamp))+"' class='"+(is_active < 150000 ? "active" : "inactive")+"'><a href='"+portal.dat+"'>"+rune+""+portal.name+"</a></ln>";
}
}
return feed_html;
}

this.get_feed = function(archive)
{
return archive.readFile('portal.json')
.then((portal_data) => {
var portal = JSON.parse(portal_data);
var last_entry = portal.feed[portal.feed.length-1];
var is_active = Math.floor((new Date() - last_entry.timestamp) / 1000);
var rune = portal.port.indexOf(r.portal.data.dat) > -1 ? "@" : "~";

if(is_active > 190000 && portal.name != r.portal.data.name){
this.feed_html += "<ln title='"+(timeSince(last_entry.timestamp))+"' class='dead' data-operation='un"+archive.gateway+"'>"+rune+""+portal.name+"</ln>";
}
else{
this.feed_html+= "<ln title='"+(timeSince(last_entry.timestamp))+"' class='"+(is_active < 150000 ? "active" : "inactive")+"'><a href='"+portal.dat+"'>"+rune+""+portal.name+"</a></ln>";
}

this.portals[portal.name] = portal;

return portal.feed
.filter((entry) => {
if (!this.filter) return true;
Expand Down

0 comments on commit 6f35221

Please sign in to comment.