Ticket #270 (closed defect: fixed)
[PATCH] send-quarantine-digests.pl bugs & enhancements
| Reported by: | erik@… | Owned by: | dmorton |
|---|---|---|---|
| Priority: | high | Milestone: | 1.0.1 |
| Component: | Perl scripts | Version: | 1.0.0 |
| Severity: | normal | Keywords: | digests, refactor, performance, empty, multiple |
| Cc: |
Description
Normally, I'd break this into 5 tickets, but I have a patch that covers all 5:
- Bugs
- The value of $at_least_one is not reset when starting to process a new user, so that once this value is set, all subsequent users generate mail.
- Because of variable scoping, if the untainting of a variable fails, it retains its previous value (notably, $user_email and $subject)
- Within the report loop, $report_count is incremented, even when $sth->rows indicates that nothing was selected. This causes @{ $vars{'list'} } to have holes.
- Enhancements
- Repeatedly PREPARE'ing the same SQL statement over & over is wasteful and unecessarily taxing on DB resources, which might be at a premium. A better solution is to prepare once and execute as many times as is necessary. Some slight refactoring of this code was necessary to facilitate that.
- get_config_values() reads the same (unchanging) values from the database every time it is called. Since it is called every time a token is generated, it's called for each line in every report. Adding a cache of these values for the lifetime of this script cuts down on DB overhead.
- Other enhancements that might actually hamper acceptance of this patch
- Code Normalization
- Indentation — 4-space indent (no tabs) seemed to be the preference
- Block brackets — no prepended newline (only had a two exceptions)
- SQL
- Refactored to allow a single PREPARE statement for each statement used more than once.
- Now stored in HERE documents, to facilitate reading & editing
- Subroutines moved to the end
- Since they're using pre-PREPARE'd statement handles, it's less obtuse if we don't have to pre-declare the variables.
- It's also awkward to have them stuck in the middle of of the main code (between user-config & the rest of the "main" block.) Prototypes are left in that space to ensure proper usage.
- Code Normalization
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

