Fossil SCM

Cache the results of calling robot_restrict() so that subsequent calls are very fast.

drh 2025-08-16 14:44 trunk
Commit 1bdda5d01d7f4779e5beb6dd3d6442783d29d8921db7f1db9dd3fd5b8b2c5f00
1 file changed +8 -2
+8 -2
--- src/robot.c
+++ src/robot.c
@@ -156,23 +156,29 @@
156156
** should not be restricted and should be rendered normally.
157157
*/
158158
int robot_restrict(const char *zPage){
159159
const char *zGlob;
160160
const char *zToken;
161
- if( g.zLogin ) return 0; /* Logged in users always get through */
161
+ static int bKnownPass = 0;
162
+ if( g.zLogin ) return 0; /* Logged in users always get through */
163
+ if( bKnownPass ) return 0; /* Already known to pass robot restrictions */
162164
zGlob = db_get("robot-restrict",robot_restrict_default());
163
- if( zGlob==0 || zGlob[0]==0 ) return 0;
165
+ if( zGlob==0 || zGlob[0]==0 ){ bKnownPass = 1; return 0; }
164166
if( !glob_multi_match(zGlob, zPage) ) return 0;
165167
zToken = P("token");
166168
if( zToken!=0
167169
&& db_exists("SELECT 1 FROM config WHERE name='token-%q'", zToken)
168170
){
171
+ bKnownPass = 1;
169172
return 0; /* There is a valid token= query parameter */
170173
}
171174
if( robot_proofofwork() ){
175
+ /* A captcha was generated. Abort this page. A redirect will occur
176
+ ** if the captcha passes. */
172177
return 1;
173178
}
179
+ bKnownPass = 1;
174180
return 0;
175181
}
176182
177183
178184
/*
179185
--- src/robot.c
+++ src/robot.c
@@ -156,23 +156,29 @@
156 ** should not be restricted and should be rendered normally.
157 */
158 int robot_restrict(const char *zPage){
159 const char *zGlob;
160 const char *zToken;
161 if( g.zLogin ) return 0; /* Logged in users always get through */
 
 
162 zGlob = db_get("robot-restrict",robot_restrict_default());
163 if( zGlob==0 || zGlob[0]==0 ) return 0;
164 if( !glob_multi_match(zGlob, zPage) ) return 0;
165 zToken = P("token");
166 if( zToken!=0
167 && db_exists("SELECT 1 FROM config WHERE name='token-%q'", zToken)
168 ){
 
169 return 0; /* There is a valid token= query parameter */
170 }
171 if( robot_proofofwork() ){
 
 
172 return 1;
173 }
 
174 return 0;
175 }
176
177
178 /*
179
--- src/robot.c
+++ src/robot.c
@@ -156,23 +156,29 @@
156 ** should not be restricted and should be rendered normally.
157 */
158 int robot_restrict(const char *zPage){
159 const char *zGlob;
160 const char *zToken;
161 static int bKnownPass = 0;
162 if( g.zLogin ) return 0; /* Logged in users always get through */
163 if( bKnownPass ) return 0; /* Already known to pass robot restrictions */
164 zGlob = db_get("robot-restrict",robot_restrict_default());
165 if( zGlob==0 || zGlob[0]==0 ){ bKnownPass = 1; return 0; }
166 if( !glob_multi_match(zGlob, zPage) ) return 0;
167 zToken = P("token");
168 if( zToken!=0
169 && db_exists("SELECT 1 FROM config WHERE name='token-%q'", zToken)
170 ){
171 bKnownPass = 1;
172 return 0; /* There is a valid token= query parameter */
173 }
174 if( robot_proofofwork() ){
175 /* A captcha was generated. Abort this page. A redirect will occur
176 ** if the captcha passes. */
177 return 1;
178 }
179 bKnownPass = 1;
180 return 0;
181 }
182
183
184 /*
185

Keyboard Shortcuts

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