Giter Club home page Giter Club logo

Comments (5)

zaggino avatar zaggino commented on August 10, 2024

There's of course something very wrong going on in there - I'll look for a fix and let you know.

from z-schema.

zaggino avatar zaggino commented on August 10, 2024

@bzuillsmith can you give me a test-case with a schema you're testing against? Seems like inner properties of ObjectID() are being validated with your schema and that's causing the delay but I can't say for sure until I see the schema.

from z-schema.

bzuillsmith avatar bzuillsmith commented on August 10, 2024

Below is an example test based on a subset of one of our use cases. Usually we add format: 'object-id that checks it's an instance of ObjectID but seems to make no difference to the problem.

On my machine, async validation takes 232ms and sync takes 200ms.

var ObjectID = require('mongodb').ObjectID;
var ZSchema = require('z-schema');

describe('z-schema', function() {
    var schema = {
        type: 'array',
        items: {
            type: 'object',
            properties: {
                'note': { type: 'string', maxLength: 2048 },
                // 'created':  { type: 'object', format: 'date-object' },
                'createdBy': { type: 'string', maxLength: 100 },
                '_id': { type: 'object' }
            },
            additionalProperties: false,
        },
        additionalItems: false,
    };

    var notes = [];

    before(function() {
        var num = 5, i;
        for(i = 0; i < num; i++) {
            notes.push({
                _id: new ObjectID(),
                note: 'Here is my note',
                createdBy: '[email protected]',
            });
        }
        return notes;
    });

    it('should be fast', function(done) {
        var validator = new ZSchema({ async: true, noTypeless: true, noExtraKeywords: true, noZeroLengthStrings: true, forceAdditional: true});
        validator.validate(notes, schema, done);
    });
});

from z-schema.

zaggino avatar zaggino commented on August 10, 2024

@bzuillsmith here's the testcase I put together: ac4ed8c

I didn't notice any major difference with using ObjectID against using simple object. Btw on my computer validation over 10000 objects (I increased from your original five) took about 250ms in sync mode and 400ms in async mode.

Can you please try to run the testcase on your machine? Just clone the repo and do

npm install
npm install -g mocha
mocha --grep "issue/39"

from z-schema.

zaggino avatar zaggino commented on August 10, 2024

Confirmed solved in ac4ed8c#commitcomment-6674756

from z-schema.

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.