-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Push overhaul #4378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Push overhaul #4378
Changes from all commits
db091ba
cd28e25
164e833
dd66e7a
a74e8bd
4483900
1ad8ee0
56fd570
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,138 @@ describe('PushWorker', () => { | |
expect(PushUtils.bodiesPerLocales({where: {}})).toEqual({default: {where: {}}}); | ||
expect(PushUtils.groupByLocaleIdentifier([])).toEqual({default: []}); | ||
}); | ||
|
||
it('should propely apply translations strings', () => { | ||
const bodies = PushUtils.bodiesPerLocales({ | ||
data: { | ||
alert: 'Yo!', | ||
}, | ||
translation: { | ||
'fr': 'frenchy!', | ||
'en': 'english', | ||
} | ||
}, ['fr', 'en']); | ||
expect(bodies).toEqual({ | ||
fr: { | ||
data: { | ||
alert: 'frenchy!', | ||
} | ||
}, | ||
en: { | ||
data: { | ||
alert: 'english', | ||
} | ||
}, | ||
default: { | ||
data: { | ||
alert: 'Yo!' | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
it('should propely apply translations objects', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again here |
||
const bodies = PushUtils.bodiesPerLocales({ | ||
data: { | ||
alert: 'Yo!', | ||
badge: 'Increment', | ||
}, | ||
translation: { | ||
'fr': { alert: 'frenchy!', title: 'yolo' }, | ||
'en': { alert: 'english', badge: 2, other: 'value' }, | ||
} | ||
}, ['fr', 'en']); | ||
expect(bodies).toEqual({ | ||
fr: { | ||
data: { | ||
alert: 'frenchy!', | ||
title: 'yolo', | ||
} | ||
}, | ||
en: { | ||
data: { | ||
alert: 'english', | ||
badge: 2, | ||
other: 'value' | ||
} | ||
}, | ||
default: { | ||
data: { | ||
alert: 'Yo!', | ||
badge: 'Increment', | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
it('should propely override alert-lang with translations', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
const bodies = PushUtils.bodiesPerLocales({ | ||
data: { | ||
alert: 'Yo!', | ||
badge: 'Increment', | ||
'alert-fr': 'Yolo!', | ||
}, | ||
translation: { | ||
'fr': { alert: 'frenchy!', title: 'yolo' }, | ||
'en': { alert: 'english', badge: 2, other: 'value' }, | ||
} | ||
}, ['fr', 'en']); | ||
expect(bodies).toEqual({ | ||
fr: { | ||
data: { | ||
alert: 'frenchy!', | ||
title: 'yolo', | ||
} | ||
}, | ||
en: { | ||
data: { | ||
alert: 'english', | ||
badge: 2, | ||
other: 'value' | ||
} | ||
}, | ||
default: { | ||
data: { | ||
alert: 'Yo!', | ||
badge: 'Increment', | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
it('should propely override alert-lang with translations strings', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
const bodies = PushUtils.bodiesPerLocales({ | ||
data: { | ||
alert: 'Yo!', | ||
badge: 'Increment', | ||
'alert-fr': 'Yolo!', | ||
'alert-en': 'Yolo!' | ||
}, | ||
translation: { | ||
'fr': 'frenchy', | ||
} | ||
}, ['fr', 'en']); | ||
expect(bodies).toEqual({ | ||
fr: { | ||
data: { | ||
alert: 'frenchy', | ||
badge: 'Increment', | ||
} | ||
}, | ||
en: { | ||
data: { | ||
alert: 'Yolo!', | ||
badge: 'Increment' | ||
} | ||
}, | ||
default: { | ||
data: { | ||
alert: 'Yo!', | ||
badge: 'Increment', | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('pushStatus', () => { | ||
|
@@ -276,7 +408,6 @@ describe('PushWorker', () => { | |
'failedPerType.ios': { __op: 'Increment', amount: 1 }, | ||
[`sentPerUTCOffset.${UTCOffset}`]: { __op: 'Increment', amount: 1 }, | ||
[`failedPerUTCOffset.${UTCOffset}`]: { __op: 'Increment', amount: 1 }, | ||
count: { __op: 'Increment', amount: -1 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're not using |
||
}); | ||
const query = new Parse.Query('_PushStatus'); | ||
return query.get(handler.objectId, { useMasterKey: true }); | ||
|
@@ -354,7 +485,6 @@ describe('PushWorker', () => { | |
'failedPerType.ios': { __op: 'Increment', amount: 1 }, | ||
[`sentPerUTCOffset.${UTCOffset}`]: { __op: 'Increment', amount: 1 }, | ||
[`failedPerUTCOffset.${UTCOffset}`]: { __op: 'Increment', amount: 1 }, | ||
count: { __op: 'Increment', amount: -1 } | ||
}); | ||
done(); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ import { ParseMessageQueue } from '../ParseMessageQueue'; | |
import rest from '../rest'; | ||
import { applyDeviceTokenExists } from './utils'; | ||
import Parse from 'parse/node'; | ||
import logger from '../logger'; | ||
|
||
const PUSH_CHANNEL = 'parse-server-push'; | ||
const DEFAULT_BATCH_SIZE = 100; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If batchSize is not needed we can just drop this too. |
||
const DEFAULT_QUERY_BATCH_SIZE = 10000; | ||
|
||
export class PushQueue { | ||
parsePublisher: Object; | ||
|
@@ -16,6 +18,7 @@ export class PushQueue { | |
constructor(config: any = {}) { | ||
this.channel = config.channel || PushQueue.defaultPushChannel(); | ||
this.batchSize = config.batchSize || DEFAULT_BATCH_SIZE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need batchSize? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah we still need it so we have a query batch size and an enqueue batch size: |
||
this.installationsQueryBatchSize = config.installationsQueryBatchSize || DEFAULT_QUERY_BATCH_SIZE; | ||
this.parsePublisher = ParseMessageQueue.createPublisher(config); | ||
} | ||
|
||
|
@@ -24,39 +27,44 @@ export class PushQueue { | |
} | ||
|
||
enqueue(body, where, config, auth, pushStatus) { | ||
const limit = this.batchSize; | ||
|
||
where = applyDeviceTokenExists(where); | ||
|
||
// Order by objectId so no impact on the DB | ||
const order = 'objectId'; | ||
return Promise.resolve().then(() => { | ||
return rest.find(config, | ||
auth, | ||
'_Installation', | ||
where, | ||
{limit: 0, count: true}); | ||
}).then(({results, count}) => { | ||
if (!results || count == 0) { | ||
const batches = []; | ||
let currentBatch = []; | ||
let total = 0; | ||
const options = { | ||
limit: this.installationsQueryBatchSize, | ||
keys: 'objectId' | ||
} | ||
return rest.each(config, auth, '_Installation', where, options, (result) => { | ||
total++; | ||
currentBatch.push(result.objectId); | ||
if (currentBatch.length == this.batchSize) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's used there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. |
||
batches.push(currentBatch); | ||
currentBatch = []; | ||
} | ||
}, { useMasterKey: true, batchSize: 10000 }).then(() => { | ||
if (currentBatch.length > 0) { | ||
batches.push(currentBatch); | ||
} | ||
return Promise.resolve({ batches, total }); | ||
}); | ||
}).then(({ batches, total }) => { | ||
if (total == 0) { | ||
return Promise.reject({error: 'PushController: no results in query'}) | ||
} | ||
pushStatus.setRunning(Math.ceil(count / limit)); | ||
let skip = 0; | ||
while (skip < count) { | ||
const query = { where, | ||
limit, | ||
skip, | ||
order }; | ||
|
||
logger.verbose(`_PushStatus ${pushStatus.objectId}: sending push to installations with %d batches`, total); | ||
batches.forEach((batch) => { | ||
const pushWorkItem = { | ||
body, | ||
query, | ||
query: { | ||
where: { objectId: { '$in': batch }}, | ||
}, | ||
pushStatus: { objectId: pushStatus.objectId }, | ||
applicationId: config.applicationId | ||
} | ||
}; | ||
this.parsePublisher.publish(this.channel, JSON.stringify(pushWorkItem)); | ||
skip += limit; | ||
} | ||
}); | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo on 'propely' 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meh.. look like I'm quite tired