Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Apply modifying entries to the queue

Imagine the following scenario:
 * An editor posts an entry
 * The user gets a nag with 1 new entry
 * The editor deletes the just-added entry
 * The entry is deleted, but since the queue isn't
touched, the user still sees the same message.

In this commit we apply all new modifying (update/delete)
entries to the queue. If we get a delete entry for an
entry in the queue, we remove it from the queue. If we
get an update entry, we just update the html of the
entry in the queue. Both of these trigger a re-render
of the fixed nag and it's always correct.
  • Loading branch information...
commit 11646fe7660f0ae8dbeeb8d27f49d1d4cb3d8283 1 parent 21c5db6
@nb nb authored
Showing with 28 additions and 6 deletions.
  1. +1 −0  HACKING.md
  2. +27 −6 js/liveblog.js
View
1  HACKING.md
@@ -7,6 +7,7 @@ In this file you'll find technical overview of how the liveblog works.
* Liveblog post – a WordPress post, which has the liveblog checbox checked, shows the liveblog entries in real time, and offers authorized users to insert new entries.
* Refresh interval – how often the client side checks for entries' updates.
* Nag – when there's a new update, we show the nag to the users, instead of loading the new entries directly. The nag contains a link to load the new entries.
+* Modifying Entry – an entry, which is not an actual entry, but updates or deletes (replaces) an existing entry.
# Major Design Decisions
* **Each entry is a comment** – adding a lot of posts quickly leads to too much cache invalidations. Comments don't have cache entry per comment, so it's much easier to create a scalable liveblog.
View
33 js/liveblog.js
@@ -28,7 +28,27 @@ window.liveblog = {};
}
liveblog.display_entries(this.models);
this.reset([]);
- }
+ },
+ applyModifyingEntries: function(entries) {
+ console.log(entries);
+ var collection = this;
+ _.each(entries, function(entry) {
+ collection.applyModifyingEntry(entry);
+ });
+ },
+ applyModifyingEntry: function(entry) {
+ var existing = this.get(entry.id);
+ if (!existing) {
+ return;
+ }
+ console.log(entry);
+ if ("delete" == entry.type) {
+ this.remove(existing);
+ }
+ if ("update" == entry.type) {
+ existing.set("html", entry.html);
+ }
+ },
});
liveblog.FixedNagView = Backbone.View.extend({
@@ -166,7 +186,7 @@ window.liveblog = {};
};
liveblog.get_recent_entries_success = function( response, status, xhr ) {
- var new_entries, existing_entries;
+ var added, modifying;
liveblog.consecutive_failures_count = 0;
@@ -183,11 +203,12 @@ window.liveblog = {};
if ( liveblog.is_at_the_top() && liveblog.queue.isEmpty() ) {
liveblog.display_entries( response.entries );
} else {
- new_entries = _.filter(response.entries, function(entry) { return 'new' == entry.type; } );
- existing_entries = _.filter(response.entries, function(entry) { return 'update' == entry.type || 'delete' == entry.type; } );
- liveblog.queue.add(new_entries);
+ added = _.filter(response.entries, function(entry) { return 'new' == entry.type; } );
+ modifying = _.filter(response.entries, function(entry) { return 'update' == entry.type || 'delete' == entry.type; } );
+ liveblog.queue.add(added);
+ liveblog.queue.applyModifyingEntries(modifying);
// updating and deleting entries is rare enough, so that we can screw the user's scroll and not queue those events
- liveblog.display_entries(existing_entries);
+ liveblog.display_entries(modifying);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.