Skip to content

Commit

Permalink
use seek pagination instead of offset
Browse files Browse the repository at this point in the history
- slightly better performance
- easier to read than extra explicitely requested entries for fixing fossar#774
  • Loading branch information
niol committed Jan 2, 2017
1 parent 12fedd2 commit 1aff08c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 14 deletions.
27 changes: 26 additions & 1 deletion daos/mysql/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,34 @@ public function get($options = array()) {
$where[] = "items.updatetime > :updatedsince ";
}

// seek pagination (alternative to offset)
if( isset($options['offset_from_datetime'])
&& strlen($options['offset_from_datetime']) > 0
&& isset($options['offset_from_id'])
&& is_numeric($options['offset_from_id']) ) {

$params[':offset_from_datetime'] = array(
$options['offset_from_datetime'], \PDO::PARAM_STR
);
$params[':offset_from_id'] = array(
$options['offset_from_id'], \PDO::PARAM_INT
);
$ltgt = null;
if( $order == 'ASC' )
$ltgt = '>';
else
$ltgt = '<';

$where[] = "(items.datetime, items.id) $ltgt (:offset_from_datetime, :offset_from_id)";
}

$where_ids = '';
// extra ids to include in stream
if( isset($options['extra_ids']) ) {
if( isset($options['extra_ids'])
&& count($options['extra_ids']) > 0
// limit the query to a sensible max
&& count($options['extra_ids']) <= \F3::get('items_perpage') ) {

$extra_ids_stmt = $this->stmt->intRowMatches('items.id',
$options['extra_ids']);
if( !is_null($extra_ids_stmt) )
Expand Down
18 changes: 16 additions & 2 deletions public/js/selfoss-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var selfoss = {
*/
filter: {
offset: 0,
offset_from_datetime: null,
offset_from_id: null,
itemsPerPage: 0,
search: '',
type: 'newest',
Expand Down Expand Up @@ -147,6 +149,19 @@ var selfoss = {
return true;
return false;
},


/**
* reset filter
*
* @return void
*/
filterReset: function() {
selfoss.filter.offset = 0;
selfoss.filter.offset_from_datetime = null;
selfoss.filter.offset_from_id = null;
selfoss.filter.extra_ids.length = 0;
},


/**
Expand Down Expand Up @@ -434,8 +449,7 @@ var selfoss = {

// close opened entry and list
location.hash = selfoss.events.path;
selfoss.filter.extra_ids.length = 0;
selfoss.filter.offset = 0;
selfoss.filterReset();

$.ajax({
url: $('base').attr('href') + 'mark',
Expand Down
4 changes: 3 additions & 1 deletion public/js/selfoss-events-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ selfoss.events.entries = function(e) {
// more
$('.stream-more').unbind('click').click(function () {
var streamMore = $(this);
selfoss.filter.offset += selfoss.filter.itemsPerPage;
var lastEntry = $('.entry').filter(':last');
selfoss.filter.offset_from_datetime = lastEntry.data('entry-datetime');
selfoss.filter.offset_from_id = lastEntry.data('entry-id');

streamMore.addClass('loading');
$.ajax({
Expand Down
4 changes: 0 additions & 4 deletions public/js/selfoss-events-entriestoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ selfoss.events.entriesToolbar = function(parent) {
url: $('base').attr('href') + (unread ? 'mark/' : 'unmark/') + id,
data: { ajax: true },
type: 'POST',
success: function(data) {
if( unread )
selfoss.filter.extra_ids.push(id);
},
error: function(jqXHR, textStatus, errorThrown) {
// rollback ui changes
updateStats(!unread);
Expand Down
6 changes: 2 additions & 4 deletions public/js/selfoss-events-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ selfoss.events.search = function() {

// execute search
$('#search').removeClass('active');
selfoss.filter.offset = 0;
selfoss.filter.extra_ids.length = 0;
selfoss.filterReset();
selfoss.filter.search = term;
selfoss.reloadList();

Expand Down Expand Up @@ -90,8 +89,7 @@ selfoss.events.search = function() {
return;
}

selfoss.filter.offset = 0;
selfoss.filter.extra_ids.length = 0;
selfoss.filterReset();
selfoss.filter.search = '';
$('#search-list').hide();
$('#search-list').html('');
Expand Down
4 changes: 2 additions & 2 deletions public/js/selfoss-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ selfoss.events = {
var sourceId = parseInt(selfoss.events.subsection.substr(7));
if( sourceId ) {
selfoss.filter.source = sourceId;
selfoss.filter.sourcesNav = true;
}
}

selfoss.filter.offset = 0;
selfoss.filter.extra_ids.length = 0;
selfoss.filterReset();

$('#nav-filter-'+selfoss.events.section).click();
selfoss.reloadList();
Expand Down
1 change: 1 addition & 0 deletions templates/item.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<div id="entry<?PHP echo $this->item['id']; ?>"
data-entry-id="<?PHP echo $this->item['id']; ?>"
data-entry-source="<?PHP echo $this->item['source']; ?>"
data-entry-datetime="<?PHP echo $this->item['datetime']; ?>"
class="entry
<?PHP echo $this->item['unread']==1 ? 'unread' : ''; ?>" role="article">

Expand Down

0 comments on commit 1aff08c

Please sign in to comment.