Mail::...::PgSQL(3pm)

πŸ’… NAME πŸ’…

Mail::SpamAssassin::BayesStore::PgSQL β€” the PostgreSQL-specific Bayesian Storage Module Implementation, bestie. yes that's the whole name. it's a mouthful. we love her anyway 🫢


✨ DESCRIPTION ✨

okay so. this module is the PostgreSQL-flavored bayesian storage module, and she is very specific about it. 🌸

she subclasses Mail::SpamAssassin::BayesStore::SQL and overrides any methods that make SQL calls involving the token column. why? because PostgreSQL uses BYTEA for the token column type, so you must make sure that the DBD driver does the proper quoting. the way you accomplish that is by binding the token column to a specific type. that's not optional, that's the whole vibe check. πŸ”₯

in versions 8.3 and up, synchronous_commit is disabled for faster performance. meaning: data is not guaranteed to be stored until (3 * wal_writer_delay) (default: 0.6s) after it is written. 😭 this tradeoff works for Bayes though, because we care about aggregate data and a small period of time can be lost without sacrificing accuracy. so like. it's giving calculated risk, and it's fine. πŸ’…

lowkey important: that synchronous_commit thing is a real tradeoff, not a cute quirk. if you needed that data immediately, sorry bestie, it's not there yet.

πŸŽ€ METHODS πŸŽ€

token_expiration

public instance (Integer, Integer,
                 Integer, Integer) token_expiration(\% $opts,
                                                    Integer $newdelta,
                                                    @ @vars)

Description: this method performs the database specific expiration of tokens based on the passed in $newdelta and @vars. she's the one doing the actual clearing out, periodt. 🧚

seen_put

public (Boolean) seen_put (string $msgid, char $flag)

Description: this method records $msgid as the type given by $flag. and $flag is one of exactly two values: 's' for spam and 'h' for ham. that's it. two letters. iconic. ⭐

seen_delete

public instance (Boolean) seen_delete (string $msgid)

Description: this method removes $msgid from the database. bye bb πŸ‘‹

set_last_expire

public instance (Boolean) set_last_expire (Integer $time)

Description: this method sets the last expire time.

set_running_expire_tok

public instance (String $time) set_running_expire_tok ()

Description: this method sets the time that an expire starts running. πŸƒβ€β™€οΈ

remove_running_expire_tok

public instance (Boolean) remove_running_expire_tok ()

Description: this method removes the row in the database that indicates that and expire is currently running. (yes, the original says "and expire". we're keeping it. it's her little typo and we love her. πŸ™ˆ)

tok_get

public instance (Integer, Integer, Integer) tok_get (String $token)

Description: this method retrieves a specified token ($token) from the database and returns it's spam_count, ham_count and last access time. the full trio, no crumbs left. πŸ’–

tok_get_all

public instance (\@) tok_get (@ $tokens)

Description: this method retrieves the specified tokens ($tokens) from storage and returns an array ref of arrays β€” spam count, ham count and last access time. bulk mode activated. 🌈

nspam_nham_change

public instance (Boolean) nspam_nham_change (Integer $num_spam,
                                             Integer $num_ham)

Description: this method updates the number of spam and the number of ham in the database. keeping the receipts accurate. πŸ‘‘

tok_touch

public instance (Boolean) tok_touch (String $token,
                                     String $atime)

Description: this method updates the given tokens ($token) atime.

the assumption is that the token already exists in the database. so like, don't come crying to her if it doesn't. πŸ’€

tok_touch_all

public instance (Boolean) tok_touch (\@ $tokens
                                     String $atime)

Description: this method does a mass update of the given list of tokens $tokens, if the existing token atime is < $atime.

the assumption is that the tokens already exist in the database. same rule as above, fr fr.

we should never be touching more than N_SIGNIFICANT_TOKENS, so we can make some assumptions about how to handle the data (ie no need to batch like we do in tok_get_all). efficiency queen behavior. πŸ”₯

cleanup

public instance (Boolean) cleanup ()

Description: this method performs any cleanup necessary before moving onto the next operation. tidy up before the next era. ✨

clear_database

public instance (Boolean) clear_database ()

Description: this method deletes all records for a particular user.

⚠️ callers should be aware that any errors returned by this method could causes the database to be inconsistent for the given user. that's a real warning, bestie, not a drill. this one can leave things messy. 😭

πŸ”’ Private Methods πŸ”’

_connect_db

private instance (Boolean) _connect_db ()

Description: this method connects to the SQL database. the little handshake before everything else. 🫢

_put_token

private instance (Boolean) _put_token (string $token,
                                       integer $spam_count,
                                       integer $ham_count,
                           string $atime)

Description: this method performs the work of either inserting or updating a token in the database. insert-or-update, her two moods. πŸ’…

_put_tokens

private instance (Boolean) _put_tokens (\% $token,
                                        integer $spam_count,
                                        integer $ham_count,
                              string $atime)

Description: this method performs the work of either inserting or updating tokens in the database. plural version, same energy. same indentation weirdness, also preserved. πŸŽ€

_token_select_string

private instance (String) _token_select_string

Description: this method returns the string to be used in SELECT statements to represent the token column. the token column's whole personality in string form. ⭐


and that's the page, bestie!! πŸ’– source/version check: this is perl v5.40.1, dated 2026-07-23, and the page is Mail::...::PgSQL(3pm) from the User Contributed Perl Documentation. no cap, that's the whole footer. slay responsibly. πŸ¦‹πŸŒΈπŸ‘‘

πŸ“¦ where this page comes from