* 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)
| 752 | * to avoid cache hits on the RE2JS compile step. |
| 753 | */ |
| 754 | async 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) |
nothing calls this directly
no test coverage detected