Merge pull request #23 from rtyler/id-sort

Avoid feathers-sequelize pagination which is bad
This commit is contained in:
R. Tyler Croy 2018-10-25 13:09:37 -07:00 committed by GitHub
commit a01c698485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -13,7 +13,7 @@ export default (app) => {
async (req, res, next) => {
const query = Object.assign({
$sort: {
createdAt: -1,
id: -1,
}
}, req.query);
const user = (req as any).user;

View File

@ -20,6 +20,20 @@ export const eventsHooks : HooksObject = {
find: [
authorize(),
applyGrant(),
/*
* Pagination for feathers-sequelize relies on Model.findAndCountAll()
* which implements superslow SELECT COUNT(DISTINCT(id)) FROM events
* queries against the super-big database tables in production.
*
* Rather than rely on pagination, we'll simply add our limit and let the
* front-end go forwards and backwards, but never discover the total
* number of pages
*/
(context) => {
Object.assign(context.params.query, {
$limit: 25,
});
},
],
get: [
authorize(),
@ -65,8 +79,6 @@ export default (app : Application) => {
const Model : any = Event(db.sequelize, db.sequelize.Sequelize);
app.use('/events', service({
Model: Model,
paginate: {
default: 25,
}}));
}));
app.service('events').hooks(eventsHooks);
};

View File

@ -27,10 +27,9 @@ html(lang="en")
li.list-inline-item
a(href='/dashboard', title='Reset the filter query').
Reset query
if events.total > events.limit
li.list-inline-item
a(href='?id[$lt]=' + events.data[events.data.length - 1].id, title='View the next page of results').
Next
li.list-inline-item
a(href='?id[$lt]=' + events[events.length - 1].id, title='View the next page of results').
Next
table.table-dark.table.table-striped.table-borderd.table-hover
tr
th(scope='col').text-center ID  
@ -48,7 +47,7 @@ html(lang="en")
option(value=t.type) #{t.type}
th(scope='col').text-center Payload
th(scope='col').text-center Actions
each e in events.data
each e in events
tr
td.text-center.
#{e.id}