Skip to content

Commit

Permalink
Merge 4524819 into f7d2e09
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis committed Mar 15, 2021
2 parents f7d2e09 + 4524819 commit e7d5e0d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ ___
- Test Parse Server continuously against all relevant Postgres versions (minor versions), added Postgres compatibility table to Parse Server docs (Corey Baker) [#7176](https://github.com/parse-community/parse-server/pull/7176)
- Randomize test suite (Diamond Lewis) [#7265](https://github.com/parse-community/parse-server/pull/7265)
- LDAP: Properly unbind client on group search error (Diamond Lewis) [#7265](https://github.com/parse-community/parse-server/pull/7265)
- Improve data consistency in Push and Job Status update (Diamond Lewis) [#7267](https://github.com/parse-community/parse-server/pull/7267)
___
## 4.5.0
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import redis from 'redis';
import logger from '../../../logger';
import { KeyPromiseQueue } from './KeyPromiseQueue';
import logger from '../../logger';
import { KeyPromiseQueue } from '../../KeyPromiseQueue';

const DEFAULT_REDIS_TTL = 30 * 1000; // 30 seconds in milliseconds
const FLUSH_DB_KEY = '__flush_db__';
Expand Down
File renamed without changes.
40 changes: 14 additions & 26 deletions src/StatusHandler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { md5Hash, newObjectId } from './cryptoUtils';
import { KeyPromiseQueue } from './KeyPromiseQueue';
import { logger } from './logger';
import rest from './rest';
import Auth from './Auth';

const PUSH_STATUS_COLLECTION = '_PushStatus';
const JOB_STATUS_COLLECTION = '_JobStatus';

const pushPromiseQueue = new KeyPromiseQueue();
const jobPromiseQueue = new KeyPromiseQueue();

const incrementOp = function (object = {}, key, amount = 1) {
if (!object[key]) {
object[key] = { __op: 'Increment', amount: amount };
Expand All @@ -28,22 +32,14 @@ export function flatten(array) {
}

function statusHandler(className, database) {
let lastPromise = Promise.resolve();

function create(object) {
lastPromise = lastPromise.then(() => {
return database.create(className, object).then(() => {
return Promise.resolve(object);
});
return database.create(className, object).then(() => {
return Promise.resolve(object);
});
return lastPromise;
}

function update(where, object) {
lastPromise = lastPromise.then(() => {
return database.update(className, where, object);
});
return lastPromise;
return jobPromiseQueue.enqueue(where.objectId, () => database.update(className, where, object));
}

return Object.freeze({
Expand All @@ -53,29 +49,21 @@ function statusHandler(className, database) {
}

function restStatusHandler(className, config) {
let lastPromise = Promise.resolve();
const auth = Auth.master(config);
function create(object) {
lastPromise = lastPromise.then(() => {
return rest.create(config, auth, className, object).then(({ response }) => {
// merge the objects
return Promise.resolve(Object.assign({}, object, response));
});
return rest.create(config, auth, className, object).then(({ response }) => {
return { ...object, ...response };
});
return lastPromise;
}

function update(where, object) {
// TODO: when we have updateWhere, use that for proper interfacing
lastPromise = lastPromise.then(() => {
return rest
return pushPromiseQueue.enqueue(where.objectId, () =>
rest
.update(config, auth, className, { objectId: where.objectId }, object)
.then(({ response }) => {
// merge the objects
return Promise.resolve(Object.assign({}, object, response));
});
});
return lastPromise;
return { ...object, ...response };
})
);
}

return Object.freeze({
Expand Down

0 comments on commit e7d5e0d

Please sign in to comment.