Skip to content

Commit

Permalink
fix(stable-results): Order results to protect against changing result…
Browse files Browse the repository at this point in the history
… set ordering. Increase page size for better performance
  • Loading branch information
matthew-contentful committed Nov 1, 2019
1 parent 70462a5 commit 1d6a604
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/lib/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export default class Fetcher implements APIFetcher {

while (true) {
const paramsWithSkip = {
limit: '500',
order: 'sys.createdAt',
...params,
skip: skip.toString(10)
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/content-types-in-chunks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Content Type fetcher', function () {

expect(request).to.have.been.calledWith({
method: 'GET',
url: '/content_types?sys.id[in]=person,dog,cat,plant&skip=0'
url: '/content_types?limit=500&order=sys.createdAt&sys.id[in]=person,dog,cat,plant&skip=0'
})
expect(contentTypes).to.eql([
{
Expand Down
32 changes: 16 additions & 16 deletions test/unit/lib/fetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Fetcher', function () {
request
.withArgs({
method: 'GET',
url: '/entries?sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=newsArticle&skip=0'
url: '/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=newsArticle&skip=0'
})
.resolves({
skip: 0,
Expand All @@ -41,7 +41,7 @@ describe('Fetcher', function () {
request
.withArgs({
method: 'GET',
url: '/entries?sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=newsArticle&skip=4'
url: '/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=newsArticle&skip=4'
})
.resolves({
skip: 4,
Expand All @@ -57,11 +57,11 @@ describe('Fetcher', function () {

expect(request).to.have.been.calledWith({
method: 'GET',
url: '/entries?sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=newsArticle&skip=0'
url: '/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=newsArticle&skip=0'
})
expect(request).to.have.been.calledWith({
method: 'GET',
url: '/entries?sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=newsArticle&skip=4'
url: '/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=newsArticle&skip=4'
})

const result = ['item1', 'item2', 'item3', 'item4', 'item5', 'item6']
Expand All @@ -87,7 +87,7 @@ describe('Fetcher', function () {
request
.withArgs({
method: 'GET',
url: '/entries?sys.archivedAt[exists]=false&skip=0'
url: '/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&skip=0'
})
.resolves({
skip: 0,
Expand All @@ -98,7 +98,7 @@ describe('Fetcher', function () {
request
.withArgs({
method: 'GET',
url: '/entries?sys.archivedAt[exists]=false&skip=4'
url: '/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&skip=4'
})
.resolves({
skip: 4,
Expand All @@ -114,11 +114,11 @@ describe('Fetcher', function () {

expect(request).to.have.been.calledWith({
method: 'GET',
url: '/entries?sys.archivedAt[exists]=false&skip=0'
url: '/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&skip=0'
})
expect(request).to.have.been.calledWith({
method: 'GET',
url: '/entries?sys.archivedAt[exists]=false&skip=4'
url: '/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&skip=4'
})

const result = ['item1', 'item2', 'item3', 'item4', 'item5', 'item6']
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('Fetcher', function () {

expect(request).to.have.been.calledWith({
method: 'GET',
url: `/content_types?sys.id[in]=person,dog,cat,plant&skip=0`
url: `/content_types?limit=500&order=sys.createdAt&sys.id[in]=person,dog,cat,plant&skip=0`
})
expect(contentTypes).to.eql([
{
Expand Down Expand Up @@ -353,7 +353,7 @@ describe('Fetcher', function () {

expect(request).to.have.been.calledWith({
method: 'GET',
url: '/content_types?sys.id[in]=dog,owner&skip=0'
url: '/content_types?limit=500&order=sys.createdAt&sys.id[in]=dog,owner&skip=0'
})
})

Expand Down Expand Up @@ -444,7 +444,7 @@ describe('Fetcher', function () {
request
.withArgs({
method: 'GET',
url: '/locales?skip=0'
url: '/locales?limit=500&order=sys.createdAt&skip=0'
})
.resolves({
skip: 0,
Expand All @@ -455,7 +455,7 @@ describe('Fetcher', function () {
request
.withArgs({
method: 'GET',
url: '/locales?skip=2'
url: '/locales?limit=500&order=sys.createdAt&skip=2'
})
.resolves({
skip: 2,
Expand All @@ -466,7 +466,7 @@ describe('Fetcher', function () {
request
.withArgs({
method: 'GET',
url: '/locales?skip=4'
url: '/locales?limit=500&order=sys.createdAt&skip=4'
})
.resolves({
skip: 4,
Expand All @@ -480,15 +480,15 @@ describe('Fetcher', function () {

expect(request).to.have.been.calledWith({
method: 'GET',
url: '/locales?skip=0'
url: '/locales?limit=500&order=sys.createdAt&skip=0'
})
expect(request).to.have.been.calledWith({
method: 'GET',
url: '/locales?skip=2'
url: '/locales?limit=500&order=sys.createdAt&skip=2'
})
expect(request).to.have.been.calledWith({
method: 'GET',
url: '/locales?skip=4'
url: '/locales?limit=500&order=sys.createdAt&skip=4'
})

const result = ['a', 'b', 'c', 'd', 'e', 'f']
Expand Down
12 changes: 6 additions & 6 deletions test/unit/lib/migration-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Migration parser', function () {
describe('when transforming content', function () {
it('returns all collected errors', async function () {
const fakeMakeRequest = (config) => {
if (config.url === '/content_types?sys.id[in]=foo,cat&skip=0') {
if (config.url === '/content_types?limit=500&order=sys.createdAt&sys.id[in]=foo,cat&skip=0') {
return {
total: 2,
skip: 0,
Expand All @@ -25,7 +25,7 @@ describe('Migration parser', function () {
}
}

if (config.url.indexOf('/entries?sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=foo,cat&skip=0') !== -1) {
if (config.url.indexOf('/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=foo,cat&skip=0') !== -1) {
return {
total: 2,
skip: 0,
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('Migration parser', function () {
}
}

if (config.url === '/locales?skip=0') {
if (config.url === '/locales?limit=500&order=sys.createdAt&skip=0') {
return {
total: 1,
skip: 0,
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('Migration parser', function () {
describe('when shouldPublish is false', function () {
it('does not produce publish requests', async function () {
const fakeMakeRequest = (config) => {
if (config.url === '/content_types?sys.id[in]=foo&skip=0') {
if (config.url === '/content_types?limit=500&order=sys.createdAt&sys.id[in]=foo&skip=0') {
return {
total: 1,
skip: 0,
Expand All @@ -130,7 +130,7 @@ describe('Migration parser', function () {
}
}

if (config.url === '/entries?sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=foo&skip=0') {
if (config.url === '/entries?limit=500&order=sys.createdAt&sys.archivedAt[exists]=false&sys.contentType.sys.id[in]=foo&skip=0') {
return {
total: 2,
skip: 0,
Expand All @@ -154,7 +154,7 @@ describe('Migration parser', function () {
}
}

if (config.url === '/locales?skip=0') {
if (config.url === '/locales?limit=500&order=sys.createdAt&skip=0') {
return {
total: 1,
skip: 0,
Expand Down

0 comments on commit 1d6a604

Please sign in to comment.