]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix storage-size counting of non-local/non-session kvvfs storage. Rename the 'global...
authorstephan <stephan@noemail.net>
Sat, 22 Nov 2025 16:29:45 +0000 (16:29 +0000)
committerstephan <stephan@noemail.net>
Sat, 22 Nov 2025 16:29:45 +0000 (16:29 +0000)
FossilOrigin-Name: 61606be2ae2b0d73cdcd7947a77c7ad87cdf850bba90b0c3e3cdf8c02177db73

ext/wasm/GNUmakefile
ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js
ext/wasm/tester1.c-pp.js
manifest
manifest.uuid

index 82c3913b7b29e9824c82dd831139dcfcd9000477..dd9b625a75b79c8f4d0ca4a733a99c1d7e3ee97f 100644 (file)
@@ -998,7 +998,8 @@ endif
 ########################################################################
 
 EXPORTED_FUNCTIONS.fiddle = $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle
-$(EXPORTED_FUNCTIONS.fiddle): $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE_LIST)
+$(EXPORTED_FUNCTIONS.fiddle): $(EXPORTED_FUNCTIONS.api.in) \
+ $(MAKEFILE_LIST) $(bin.c-pp)
        @$(call b.mkdir@)
        @$(call b.c-pp.shcmd,filter,$(EXPORTED_FUNCTIONS.api.in),\
       $@,$(EXPORTED_FUNCTIONS.c-pp.flags) -Dfiddle)
index 8e907e3e36e9ff1aadff2d21ed691106452d8746..d3aae3b384c133b1858e2137d185f4b7d72acbec 100644 (file)
@@ -102,7 +102,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
 
   /**
      Map of JS-stringified KVVfsFile::zClass names to
-     reference-counted Storage objects. These objects are creates in
+     reference-counted Storage objects. These objects are created in
      xOpen(). Their refcount is decremented in xClose(), and the
      record is destroyed if the refcount reaches 0. We refcount so
      that concurrent active xOpen()s on a given name, and within a
@@ -110,7 +110,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
   */
   cache.jzClassToStorage = Object.assign(Object.create(null),{
     /* Start off with mappings for well-known names. */
-    global: {
+    localThread: {
       refc: 3/*never reaches 0*/,
       s: new TransientStorage
     }
@@ -152,11 +152,10 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
 
      It returns an object in the form:
 
-     .prefix = the key prefix for this storage: "kvvfs-"+which.
-     (FIXME: we need to teach the underlying pieces to elide the
-     "-..." part for non-sessionSession/non-localStorage entries.
-     If we don't, each storage's keys will always be prefixed
-     by their name, which is wasteful.)
+     .prefix = the key prefix for this storage. Typically
+     ("kvvfs-"+which) for persistent storage and "kvvfs-" for
+     transient. (The former is historical, retained for backwards
+     compatibility.)
 
      .stores = [ array of Storage-like objects ]. Will only have >1
      element if which is falsy, in which case it contains (if called
@@ -172,7 +171,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
       const s = cache.jzClassToStorage[which];
       if( s ){
         //debug("kvvfsWhich",s.jzClass,rc.prefix, s.s);
-        rc.prefix = 'kvvfs-'+s.jzClass;
+        if( !s.useFullZClass ){
+          rc.prefix = 'kvvfs-';
+        }
         rc.stores.push(s.s);
       }
     }else{
@@ -243,7 +244,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
   capi.sqlite3_js_kvvfs_size = function(which=""){
     let sz = 0;
     const store = kvvfsWhich(which);
+    //warn("kvvfs_size storage",store);
     store?.stores?.forEach?.((s)=>{
+      //warn("kvvfs_size backend",s);
       let i;
       for(i = 0; i < s.length; ++i){
         const k = s.key(i);
@@ -727,7 +730,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
           return rc;
         }
       }
-    }
+      jdb.testKvvfsWhich = kvvfsWhich;
+    }/* __isUnderTest */
   }/*sqlite3.oo1.JsStorageDb*/
 
 })/*globalThis.sqlite3ApiBootstrap.initializers*/;
index 16ab377b3dac9f271891c10360c06b91794b7ae9..17a905e11b369a656d9a367dc63008e4e1bce1ad 100644 (file)
@@ -2882,10 +2882,15 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
       name: 'kvvfs sessionStorage',
       predicate: ()=>(globalThis.sessionStorage || "sessionStorage is unavailable"),
       test: function(sqlite3){
-        const filename = this.kvvfsDbFile = 'session';
+        const JDb = sqlite3.oo1.JsStorageDb;
         const pVfs = capi.sqlite3_vfs_find('kvvfs');
         T.assert(looksLikePtr(pVfs));
-        const JDb = sqlite3.oo1.JsStorageDb;
+        let x = JDb.testKvvfsWhich('');
+        T.assert( 2 === x?.stores?.length )
+          .assert( x.stores.indexOf(globalThis.sessionStorage)>-1 )
+          .assert( x.stores.indexOf(globalThis.localStorage)>-1 )
+          .assert( 'kvvfs-' === x.prefix );
+        const filename = this.kvvfsDbFile = 'session';
         const unlink = this.kvvfsUnlink = ()=>JDb.clearStorage(filename);
         unlink();
         let db = new JDb(filename);
@@ -2894,7 +2899,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
             'create table kvvfs(a);',
             'insert into kvvfs(a) values(1),(2),(3)'
           ]);
-          T.assert(3 === db.selectValue('select count(*) from kvvfs'));
+          T.assert(3 === db.selectValue('select count(*) from kvvfs'))
+            .assert( db.storageSize() > 0, "Db size counting is broken" );
           db.close();
           db = undefined;
           db = new JDb(filename);
@@ -2908,7 +2914,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
     .t({
       name: 'transient kvvfs',
       test: function(sqlite3){
-        const filename = 'global' /* preinstalled instance */;
+        const filename = 'localThread' /* preinstalled instance */;
         const JDb = sqlite3.oo1.JsStorageDb;
         JDb.clearStorage(filename);
         let db = new JDb(filename);
@@ -2935,6 +2941,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
           db = new JDb('new-storage');
           db.exec(sqlSetup);
           T.assert(3 === db.selectValue('select count(*) from kvvfs'));
+          console.debug("kvvfs to Object:",db.testDbToObject());
+          const n = db.storageSize();
+          T.assert( n>0, "Db size count failed" );
           close();
 
           T.mustThrow(function(){
index bce3dbeea0ca90fa0a0bdc13729490b614a39cc7..61044f1e6e18b9b54807946d60e404871f54e630 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Incremental\swork\son\skvvfs\sv2.
-D 2025-11-22T07:35:36.321
+C Fix\sstorage-size\scounting\sof\snon-local/non-session\skvvfs\sstorage.\sRename\sthe\s'global'\sbuildin\skvvfs\sstorage\sobject\sto\s'localThread'.
+D 2025-11-22T16:29:45.039
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -578,7 +578,7 @@ F ext/session/sessionwor.test 6fd9a2256442cebde5b2284936ae9e0d54bde692d0f5fd009e
 F ext/session/sqlite3session.c b3de195ce668cace9b324599bf6255a70290cbfb5451e826e946f3aee6e64c54
 F ext/session/sqlite3session.h 7404723606074fcb2afdc6b72c206072cdb2b7d8ba097ca1559174a80bc26f7a
 F ext/session/test_session.c 8766b5973a6323934cb51248f621c3dc87ad2a98f023c3cc280d79e7d78d36fb
-F ext/wasm/GNUmakefile bff7f432a65bc5152ae5aaf19f480dd16fa7fdd11a451773b7dbcac544c703b3
+F ext/wasm/GNUmakefile 58b851cb13559027499f25050a8c4a103b4c674d97f2ce4e75f2acc8cb112de7
 F ext/wasm/README-dist.txt f01081a850ce38a56706af6b481e3a7878e24e42b314cfcd4b129f0f8427066a
 F ext/wasm/README.md 2e87804e12c98f1d194b7a06162a88441d33bb443efcfe00dc6565a780d2f259
 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff
@@ -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 f6eeaeccd0a6e1fd3fe58dba8e09954a32f8f7097fae4c00e519d91a72c7be1d
+F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js 31f6241415322d5e52bca4137a63f1f942f61a301041ac99209cc1ae7be0e780
 F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 26cb41d5a62f46a106b6371eb00fef02de3cdbfaa51338ba087a45f53028e0d0
 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js aa330fa0e8ef35cbd92eb0d52e05fbaa07e61540c5cb164e693c82428ce1d763
 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js 9097074724172e31e56ce20ccd7482259cf72a76124213cbc9469d757676da86
@@ -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 4bb05703aa335a14ce1c177c05d93a2d33031ad6b8db2f59cd6d5b26e93cc1fe
+F ext/wasm/tester1.c-pp.js 9b353e5fa54452f5b08d07176bf62240d4d2237bc8c71cfa259b1a7ba1081424
 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
@@ -2178,8 +2178,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 d2bf96d68c6cb2ae68558722edb22192fb1dbbf08fefdb2fd0a4827688e082a8
-R edd2150137694760800c3d7cae9ac6f3
+P 60d61cf383b63b25dcfbf8da9539aaec253b6618ec83403f6690b7a32c13363d
+R f4dec3381eda83446cf2c6e058cf08f3
 U stephan
-Z 821185e1e7c2969ce068a864d05b8e47
+Z 4b959ef5ec765dd5696e7126989a4850
 # Remove this line to create a well-formed Fossil manifest.
index 3f7d6d560ec98698fb4a5bec3138a716866a650d..8e703377cd4a245289183fc4cca6715672c37693 100644 (file)
@@ -1 +1 @@
-60d61cf383b63b25dcfbf8da9539aaec253b6618ec83403f6690b7a32c13363d
+61606be2ae2b0d73cdcd7947a77c7ad87cdf850bba90b0c3e3cdf8c02177db73