Fossil SCM

Use a cached statement in forumpost_head_rid() because it's used frequently checking for closed tags and (now) attachments.

stephan 2026-05-22 20:56 UTC forum-attachments
Commit 1e10be4821dff1f252978b90d462affb8f8f3f2ebe7a3c14800e2be5315caa90
1 file changed +14 -9
+14 -9
--- src/forum.c
+++ src/forum.c
@@ -81,33 +81,38 @@
8181
db_reset(&q);
8282
return res;
8383
}
8484
8585
/*
86
-** Given a valid forumpost.fpid value, this function returns the first
87
-** fpid in the chain of edits for that forum post, or rid if no prior
88
-** versions are found.
86
+** Given a valid forumpost.fpid value, this function returns the
87
+** initial forumpost.fpid in the chain of edits for that forum post,
88
+** or rid if no prior versions are found.
8989
*/
9090
int forumpost_head_rid(int rid){
91
- Stmt q;
91
+ static Stmt q = empty_Stmt_m;
9292
int rcRid = rid;
93
-
94
- db_prepare(&q, "SELECT fprev FROM forumpost"
95
- " WHERE fpid=:rid AND fprev IS NOT NULL");
93
+ if( !q.pStmt ){
94
+ db_static_prepare(&q,
95
+ "SELECT fprev FROM forumpost"
96
+ " WHERE fpid=:rid AND fprev IS NOT NULL"
97
+ );
98
+ }
9699
db_bind_int(&q, ":rid", rid);
97100
while( SQLITE_ROW==db_step(&q) ){
98101
rcRid = db_column_int(&q, 0);
99102
db_reset(&q);
100103
db_bind_int(&q, ":rid", rcRid);
101104
}
102
- db_finalize(&q);
105
+ db_reset(&q);
103106
return rcRid;
104107
}
105108
106109
/*
107110
** Works like forumpost_head_rid() but expects zUuid to be an
108
-** unambiguous forum post name.
111
+** unambiguous forum post name. It may be a hash prefix, so long as
112
+** it's unambiguous. Returns 0 if the name cannot be unambiguously
113
+** resolved as a forum post.
109114
*/
110115
int forumpost_head_rid2(const char *zUuid){
111116
const int fpid = symbolic_name_to_rid(zUuid, "f");
112117
return fpid>0
113118
? forumpost_head_rid(fpid)
114119
--- src/forum.c
+++ src/forum.c
@@ -81,33 +81,38 @@
81 db_reset(&q);
82 return res;
83 }
84
85 /*
86 ** Given a valid forumpost.fpid value, this function returns the first
87 ** fpid in the chain of edits for that forum post, or rid if no prior
88 ** versions are found.
89 */
90 int forumpost_head_rid(int rid){
91 Stmt q;
92 int rcRid = rid;
93
94 db_prepare(&q, "SELECT fprev FROM forumpost"
95 " WHERE fpid=:rid AND fprev IS NOT NULL");
 
 
 
96 db_bind_int(&q, ":rid", rid);
97 while( SQLITE_ROW==db_step(&q) ){
98 rcRid = db_column_int(&q, 0);
99 db_reset(&q);
100 db_bind_int(&q, ":rid", rcRid);
101 }
102 db_finalize(&q);
103 return rcRid;
104 }
105
106 /*
107 ** Works like forumpost_head_rid() but expects zUuid to be an
108 ** unambiguous forum post name.
 
 
109 */
110 int forumpost_head_rid2(const char *zUuid){
111 const int fpid = symbolic_name_to_rid(zUuid, "f");
112 return fpid>0
113 ? forumpost_head_rid(fpid)
114
--- src/forum.c
+++ src/forum.c
@@ -81,33 +81,38 @@
81 db_reset(&q);
82 return res;
83 }
84
85 /*
86 ** Given a valid forumpost.fpid value, this function returns the
87 ** initial forumpost.fpid in the chain of edits for that forum post,
88 ** or rid if no prior versions are found.
89 */
90 int forumpost_head_rid(int rid){
91 static Stmt q = empty_Stmt_m;
92 int rcRid = rid;
93 if( !q.pStmt ){
94 db_static_prepare(&q,
95 "SELECT fprev FROM forumpost"
96 " WHERE fpid=:rid AND fprev IS NOT NULL"
97 );
98 }
99 db_bind_int(&q, ":rid", rid);
100 while( SQLITE_ROW==db_step(&q) ){
101 rcRid = db_column_int(&q, 0);
102 db_reset(&q);
103 db_bind_int(&q, ":rid", rcRid);
104 }
105 db_reset(&q);
106 return rcRid;
107 }
108
109 /*
110 ** Works like forumpost_head_rid() but expects zUuid to be an
111 ** unambiguous forum post name. It may be a hash prefix, so long as
112 ** it's unambiguous. Returns 0 if the name cannot be unambiguously
113 ** resolved as a forum post.
114 */
115 int forumpost_head_rid2(const char *zUuid){
116 const int fpid = symbolic_name_to_rid(zUuid, "f");
117 return fpid>0
118 ? forumpost_head_rid(fpid)
119

Keyboard Shortcuts

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