Currently, the robotstxt variable is set in robotstxt_install(). This disagrees with core practices and standards. Additionally, consider the following scenario:
- User has changed their ./robots.txt file with some custom additions (call it revision A).
- User installs the robotstxt module, but doesn't actually visit the configuration pages. The 'robotstxt' variable is set to the content of ./robots.txt revision A.
- User forgets they have the robotstxt module enabled and makes another addition to their ./robots.txt file (call it revision B).
- When the robots.txt path is loaded by the module, the content that is shown is revision A.
- User is confused as to why revision B is not shown.
Since the user never went to admin/settings/robotstxt and pressed 'Save configuration', the proper way would to not set the variable on install, and always check if the variable has content, and if not, load data from the ./robots.txt files.
Does that makes sense?
| Comment | File | Size | Author |
|---|---|---|---|
| 0-robotstxt-remove-install-D6.patch | 937 bytes | dave reid |
Comments
Comment #1
dave reidComment #2
hass commentedNo, it's too expensive to read the robots.txt file on every page request. This is why the file is imported in install. Variables table is cached.
Comment #3
hass commentedComment #4
dave reidI didn't consider that. Let me do some actual benchmarks first and if it's a noticeable different, I'll mark this back as by design.
Comment #5
hass commentedI'm pretty sure I will not change my mind about this as it also overcomplicates the way how we throw the warning message on the configuration page and you haven't added the fall back logic to read the root's robots.txt on install (if it may exists) and if not exists the modules robots.txt. Normally the file should not exists, but a support case have shown that we need to write this install step down... Don't waste your time :-).
Comment #6
dave reidHere's the benchmarks using
ab -n 500 http://mysql.drupal6.local/robots.txt:READING FROM ./robots.txt (bypass module)
READING FROM saved 'robotstxt' variable
READING FROM sites/all/modules/robotstxt/robots.txt
So per request, the variable has only a 170 ms over reading from the file. That's well within the margin of error for the benchmarks and shows that there is really no advantage to setting the variable on install.
Comment #7
hass commentedHow have you tested this? You need to compare the below 3 scenarios. I don't expect that you have used two file exists checks and this is faster than the DB check... and as you said there is no advantage to setting and therefore we can stay with the setting as it's much easier to maintain and use for the drupal_set_message() and other reasons. So - by design.
Scenario 1 (current):
1. Read the cached variable from DB -> display the content
Scenario 2:
1. File exists ./robots.txt? Yes -> display the content
Scenario 3 (typical after the change):
1. File exists ./robots.txt? No -> jump to #2
2. File exists [module folder]/robots.txt? Yes -> display the content