Giter VIP home page Giter VIP logo

Comments (4)

parse-github-assistant avatar parse-github-assistant commented on June 3, 2024

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

from parse-sdk-js.

mortenmo avatar mortenmo commented on June 3, 2024

I did make this hacky fix locally to fix the problem and it does, but not sure if its the best fix:

fixParse.ts

type QueueObject = {
    queueId: string;
    action: string;
    object: Parse.Object;
    serverOptions: any;
    id: string;
    className: string;
    hash: string;
    createdAt: Date;
};

console.info('Fixing Parse...');

// @ts-ignore
Parse.EventuallyQueue.enqueue = async function (
    action: string,
    object: Parse.Object,
    serverOptions: any,
): Promise<void> {
    console.log(`Enqueueing ${action} for ${object.id}`);
    const queueData = await this.getQueue();
    // @ts-ignore
    const queueId = this.generateQueueId(action, object);

    // @ts-ignore
    let index = this.queueItemExists(queueData, queueId);
    if (index > -1) {
        // Add cached values to new object if they don't exist
        for (const prop in queueData[index].object) {
            if (typeof object.get(prop) === 'undefined') {
                object.set(prop, queueData[index].object[prop]);
            }
        }
    } else {
        index = queueData.length;
    }
    queueData[index] = {
        queueId,
        action,
        // @ts-ignore
        object: object._getSaveJSON(),
        serverOptions,
        id: object.id,
        className: object.className,
        hash: object.get('hash'),
        createdAt: new Date(),
    };
    // @ts-ignore
    return this.setQueue(queueData);
};

// @ts-ignore
Parse.EventuallyQueue.sendQueueCallback = async function (
    object: Parse.Object,
    queueObject: QueueObject,
): Promise<void> {
    if (!object) {
        // @ts-ignore
        return this.remove(queueObject.queueId);
    }
    switch (queueObject.action) {
        case 'save':
            // Queued update was overwritten by other request. Do not save
            if (
                typeof object.updatedAt !== 'undefined' &&
                object.updatedAt > queueObject.createdAt
            ) {
                // @ts-ignore
                return this.remove(queueObject.queueId);
            }
            try {
                await object.save(
                    queueObject.object,
                    queueObject.serverOptions,
                );
                // @ts-ignore
                await this.remove(queueObject.queueId);
            } catch (e) {
                if (
                    e.message !==
                    'XMLHttpRequest failed: "Unable to connect to the Parse API"'
                ) {
                    // @ts-ignore
                    await this.remove(queueObject.queueId);
                }
            }
            break;
        case 'destroy':
            try {
                await object.destroy(queueObject.serverOptions);
                // @ts-ignore
                await this.remove(queueObject.queueId);
            } catch (e) {
                if (
                    e.message !==
                    'XMLHttpRequest failed: "Unable to connect to the Parse API"'
                ) {
                    // @ts-ignore
                    await this.remove(queueObject.queueId);
                }
            }
            break;
    }
};

export {};

from parse-sdk-js.

dplewis avatar dplewis commented on June 3, 2024

@mortenmo Do you want to open a pull request?

from parse-sdk-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.