MCPcopy
hub / github.com/parse-community/parse-server / benchmarkLiveQueryRegex

Function benchmarkLiveQueryRegex

benchmark/performance.js:754–798  ·  view source on GitHub ↗

* Benchmark: LiveQuery $regex end-to-end * * Measures the full round-trip of a LiveQuery subscription with a $regex constraint: * subscribe with a unique regex pattern, save an object that matches, and measure * the time until the LiveQuery event fires. Each iteration uses a different regex * t

(name)

Source from the content-addressed store, hash-verified

752 * to avoid cache hits on the RE2JS compile step.
753 */
754async function benchmarkLiveQueryRegex(name) {
755 // Enable LiveQuery on the running server
756 const { default: ParseServer } = require('../lib/index.js');
757 const liveQueryServer = await ParseServer.createLiveQueryServer(httpServer, {
758 appId: APP_ID,
759 masterKey: MASTER_KEY,
760 serverURL: SERVER_URL,
761 });
762 Parse.liveQueryServerURL = 'ws://localhost:1337';
763
764 let counter = 0;
765
766 // Cycle through different regex patterns to avoid RE2JS cache hits
767 const patterns = [
768 { base: '^BenchLQ_', fieldValue: i => `BenchLQ_${i} data` },
769 { base: 'benchfield_', fieldValue: i => `some benchfield_${i} here` },
770 { base: '[a-z]+_benchclass_', fieldValue: i => `abc_benchclass_${i}` },
771 ];
772
773 try {
774 return await measureOperation({
775 name,
776 iterations: 500,
777 operation: async () => {
778 const idx = counter++;
779 const pattern = patterns[idx % patterns.length];
780 const regex = pattern.base + idx;
781 const query = new Parse.Query('BenchmarkLiveQuery');
782 query._addCondition('field', '$regex', regex);
783 const subscription = await query.subscribe();
784 const eventPromise = new Promise(resolve => {
785 subscription.on('create', () => resolve());
786 });
787 const obj = new Parse.Object('BenchmarkLiveQuery');
788 obj.set('field', pattern.fieldValue(idx));
789 await obj.save();
790 await eventPromise;
791 subscription.unsubscribe();
792 },
793 });
794 } finally {
795 await liveQueryServer.shutdown();
796 Parse.liveQueryServerURL = undefined;
797 }
798}
799
800/**
801 * Benchmark: Object.save with nested data (denylist scanning)

Callers

nothing calls this directly

Calls 6

measureOperationFunction · 0.85
createLiveQueryServerMethod · 0.80
shutdownMethod · 0.80
subscribeMethod · 0.65
unsubscribeMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected