From: stephan Date: Sat, 29 Nov 2025 23:29:30 +0000 (+0000) Subject: Fix kvvfs event notification to notify _all_ listeners and optimize better for the... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8416526f0fe6bbe5f8a1631bf3b4e1f83e415bf;p=thirdparty%2Fsqlite.git Fix kvvfs event notification to notify _all_ listeners and optimize better for the common case of no listeners. Squelch some debug output. FossilOrigin-Name: 989d097b1324cf712107bb81697fa8e9044aea0e7feacf0e6b6561e216f07989 --- diff --git a/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js index ee4ebe0193..fd4703a2cb 100644 --- a/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js @@ -283,10 +283,10 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ */ files: [], /** - A list of objects with various event callbacks. See - sqlite3_js_kvvfs_listen(). - */ - listeners: [] + If set, it's an array of objects with various event + callbacks. See sqlite3_js_kvvfs_listen(). + */ + listeners: undefined }); /** @@ -384,16 +384,19 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ 'delete': key */ const notifyListeners = async function(eventName,store,...args){ - for(const v of store.listeners){ - const f = v?.[eventName]; - if( !f ) return; + if( store.listeners ){ const ev = Object.create(null); ev.storageName = store.jzClass; ev.type = eventName; - ev.data = ((args.length===1) ? args[0] : args); - try{f(ev)?.catch?.(noop)} - catch(e){ - warn("notifyListener",store.jzClass,eventName,e); + for(const ear of store.listeners){ + const f = ear?.[eventName]; + if( f ){ + ev.data = ((args.length===1) ? args[0] : args); + try{f(ev)?.catch?.(noop)} + catch(e){ + warn("notifyListeners",store.jzClass,eventName,e); + } + } } } }; @@ -1316,7 +1319,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } } if( opt.events ){ - store.listeners.push(opt.events); + (store.listeners ??= []).push(opt.events); } }; @@ -1332,8 +1335,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ */ const sqlite3_js_kvvfs_unlisten = function(opt){ const store = storageForZClass(opt?.storage); - if( store && opt.events ){ + if( store?.listeners && opt.events ){ store.listeners = store.listeners.filter((v)=>v!==opt.events); + if( !store.listeners.length ){ + store.listeners = undefined; + } } }; @@ -1509,6 +1515,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } }, xCreate: wasm.ptr.null, // eponymous only + //xCreate: true, // copy xConnect, i.e. also eponymous only xDisconnect: function(pVtab){ dbg("xDisconnect",...arguments); VT.xVtab.dispose(pVtab); @@ -1570,8 +1577,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return 0; }, xEof: function(pCursor){ - dbg("xEof",...arguments); const st = cursorState(pCursor); + dbg("xEof?="+(!st.row()),...arguments); return !st.row(); }, xFilter: function(pCursor, idxNum, idxCStr, diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index cac2a21725..4ebc4168c8 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -3144,11 +3144,13 @@ globalThis.sqlite3InitModule = sqlite3InitModule; if( 1 ){ const pageSize = 1024 * 16; - debug("Export before vacuum", exportDb(filename)); - debug("page size before vacuum", - db.selectArray( - "select page_size from pragma_page_size()" - )); + if( 0 ){ + debug("Export before vacuum", exportDb(filename)); + debug("page size before vacuum", + db.selectArray( + "select page_size from pragma_page_size()" + )); + } db.exec([ "delete from kvvfs where a=1;", "pragma page_size="+pageSize+";", @@ -3178,7 +3180,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule; T.assert(expectRows === duo.selectValue(sqlCount), "Unexpected record count."); exp = exportDb(filename); - debug("vacuumed export",exp); + if( 0 ){ + debug("vacuumed export",exp); + } }else{ expectRows = 6; } @@ -3190,7 +3194,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; importDb(exp); T.assert( kvvfs.exists(exp.name) ); db = new JDb(exp.name); - debug("column count after export",db.selectValue(sqlCount)); + //debug("column count after export",db.selectValue(sqlCount)); T.assert(expectRows === db.selectValue(sqlCount), "Unexpected record count."); @@ -3296,7 +3300,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; .assert('foo'===rc.name, "Unexpected name") .assert(1===rc.nRef, "Unexpected refcount"); db2.close(); - rc = db.selectObject("select * from sqlite_kvvfs where name='foo'"); + rc = db.selectObject("select 1 from sqlite_kvvfs where name='foo'"); T.assert(!rc, "Expecting foo storage to be gone"); }finally{ db.close(); diff --git a/manifest b/manifest index ba85da88c1..be0da1f5b5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\sWASM-side\sexport\sfor\skvvfsDecode()\sfor\spending\sprivate\suse\sin\sthe\skvvfs\sexport\sbits\sand\sensure\sthat\sit\sconsistently\sreturns\s-1\sfor\smalformed\sinput. -D 2025-11-29T23:29:07.265 +C Fix\skvvfs\sevent\snotification\sto\snotify\s_all_\slisteners\sand\soptimize\sbetter\sfor\sthe\scommon\scase\sof\sno\slisteners.\sSquelch\ssome\sdebug\soutput. +D 2025-11-29T23:29:30.618 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -600,7 +600,7 @@ F ext/wasm/api/sqlite3-api-worker1.c-pp.js 1041dd645e8e821c082b628cd8d9acf70c667 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 9654b565b346dc609b75d15337f20acfa7af7d9d558da1afeb9b6d8eaa404966 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d -F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js a1e556dd5c1769edf1be913d768a74fcfea33b4fefc70dacb9a51f32b42e5bfc +F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js 52c79574b05ee39ec01de1ba63a1ed36bece0858b817d2c405e36e19864610ad F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js a2eea6442556867b589e04107796c6e1d04a472219529eeb45b7cd221d7d048b F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 88ce2078267a2d1af57525a32d896295f4a8db7664de0e17e82dc9ff006ed8d3 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js 366596d8ff73d4cefb938bbe95bc839d503c3fab6c8335ce4bf52f0d8a7dee81 @@ -647,7 +647,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.c-pp.html 0e432ec2c0d99cd470484337066e8d27e7aee4641d97115338f7d962bf7b081a F ext/wasm/tester1.c-pp.html 52d88fe2c6f21a046030a36410b4839b632f4424028197a45a3d5669ea724ddb -F ext/wasm/tester1.c-pp.js 611c67df4ea42013f36d4c688e3482520fedd5b482effff9563b5143e68c38fe +F ext/wasm/tester1.c-pp.js 3398107cad5c548443d1978adf8d8b3ca48dd6baa0410ae26b24b016d39cf157 F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2180,8 +2180,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0358a99eedb503aaf8eff32a3143a2591081dfd3fd9eeecc51c601c98c714d6f -R c2c4dd9b9b3790425888bafc6adcde46 +P cd81cb70525edeb25c4ab287cd5fd03db08ec45fd9e4001cad5c3eadf11505ae +R 789f376fc2b96e33926a6af675a9a50c U stephan -Z 5539aebd29d265f356d1029839f5e503 +Z 375e7800f59bf74696e74b64b3cb2618 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b8352464c6..5fc82ce342 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cd81cb70525edeb25c4ab287cd5fd03db08ec45fd9e4001cad5c3eadf11505ae +989d097b1324cf712107bb81697fa8e9044aea0e7feacf0e6b6561e216f07989