Fossil SCM

Avoid a possibly unnecessary call to db_prepare() when doing a config sync.

drh 2021-12-19 23:07 synclog
Commit d57a63254c1d4177528b211ec35e38bf115d40e74cbe7deb4c3ee58b9ca6d1e8
1 file changed +10 -3
+10 -3
--- src/configure.c
+++ src/configure.c
@@ -513,10 +513,11 @@
513513
){
514514
Stmt q;
515515
Blob rec;
516516
int ii;
517517
int nCard = 0;
518
+ int bPrepped;
518519
519520
blob_zero(&rec);
520521
if( groupMask & CONFIGSET_SHUN ){
521522
db_prepare(&q, "SELECT mtime, quote(uuid), quote(scom) FROM shun"
522523
" WHERE mtime>=%lld", iStart);
@@ -647,14 +648,18 @@
647648
nCard++;
648649
blob_reset(&rec);
649650
}
650651
db_finalize(&q);
651652
}
652
- db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config"
653
- " WHERE name=:name AND mtime>=%lld", iStart);
653
+ bPrepped = 0;
654654
for(ii=0; ii<count(aConfig); ii++){
655655
if( (aConfig[ii].groupMask & groupMask)!=0 && aConfig[ii].zName[0]!='@' ){
656
+ if( !bPrepped ){
657
+ db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config"
658
+ " WHERE name=:name AND mtime>=%lld", iStart);
659
+ bPrepped = 1;
660
+ }
656661
db_bind_text(&q, ":name", aConfig[ii].zName);
657662
while( db_step(&q)==SQLITE_ROW ){
658663
blob_appendf(&rec,"%s %s value %s",
659664
db_column_text(&q, 0),
660665
db_column_text(&q, 1),
@@ -666,11 +671,13 @@
666671
blob_reset(&rec);
667672
}
668673
db_reset(&q);
669674
}
670675
}
671
- db_finalize(&q);
676
+ if( bPrepped ){
677
+ db_finalize(&q);
678
+ }
672679
return nCard;
673680
}
674681
675682
/*
676683
** Identify a configuration group by name. Return its mask.
677684
--- src/configure.c
+++ src/configure.c
@@ -513,10 +513,11 @@
513 ){
514 Stmt q;
515 Blob rec;
516 int ii;
517 int nCard = 0;
 
518
519 blob_zero(&rec);
520 if( groupMask & CONFIGSET_SHUN ){
521 db_prepare(&q, "SELECT mtime, quote(uuid), quote(scom) FROM shun"
522 " WHERE mtime>=%lld", iStart);
@@ -647,14 +648,18 @@
647 nCard++;
648 blob_reset(&rec);
649 }
650 db_finalize(&q);
651 }
652 db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config"
653 " WHERE name=:name AND mtime>=%lld", iStart);
654 for(ii=0; ii<count(aConfig); ii++){
655 if( (aConfig[ii].groupMask & groupMask)!=0 && aConfig[ii].zName[0]!='@' ){
 
 
 
 
 
656 db_bind_text(&q, ":name", aConfig[ii].zName);
657 while( db_step(&q)==SQLITE_ROW ){
658 blob_appendf(&rec,"%s %s value %s",
659 db_column_text(&q, 0),
660 db_column_text(&q, 1),
@@ -666,11 +671,13 @@
666 blob_reset(&rec);
667 }
668 db_reset(&q);
669 }
670 }
671 db_finalize(&q);
 
 
672 return nCard;
673 }
674
675 /*
676 ** Identify a configuration group by name. Return its mask.
677
--- src/configure.c
+++ src/configure.c
@@ -513,10 +513,11 @@
513 ){
514 Stmt q;
515 Blob rec;
516 int ii;
517 int nCard = 0;
518 int bPrepped;
519
520 blob_zero(&rec);
521 if( groupMask & CONFIGSET_SHUN ){
522 db_prepare(&q, "SELECT mtime, quote(uuid), quote(scom) FROM shun"
523 " WHERE mtime>=%lld", iStart);
@@ -647,14 +648,18 @@
648 nCard++;
649 blob_reset(&rec);
650 }
651 db_finalize(&q);
652 }
653 bPrepped = 0;
 
654 for(ii=0; ii<count(aConfig); ii++){
655 if( (aConfig[ii].groupMask & groupMask)!=0 && aConfig[ii].zName[0]!='@' ){
656 if( !bPrepped ){
657 db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config"
658 " WHERE name=:name AND mtime>=%lld", iStart);
659 bPrepped = 1;
660 }
661 db_bind_text(&q, ":name", aConfig[ii].zName);
662 while( db_step(&q)==SQLITE_ROW ){
663 blob_appendf(&rec,"%s %s value %s",
664 db_column_text(&q, 0),
665 db_column_text(&q, 1),
@@ -666,11 +671,13 @@
671 blob_reset(&rec);
672 }
673 db_reset(&q);
674 }
675 }
676 if( bPrepped ){
677 db_finalize(&q);
678 }
679 return nCard;
680 }
681
682 /*
683 ** Identify a configuration group by name. Return its mask.
684

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button