More memcache cleanup and add threads to memcache.

This commit is contained in:
Retro_Guy 2024-05-10 03:24:13 -07:00
parent ea5a32cb1e
commit b0b1ba8b69
3 changed files with 57 additions and 21 deletions

View File

@ -67,7 +67,22 @@ function thread_pageselect($group, $article_count, $first)
*/
function thread_cache_load($group)
{
global $spooldir, $compress_spoolfiles;
global $spooldir, $config_dir, $logdir, $compress_spoolfiles;
if (file_exists($config_dir . '/memcache.inc.php')) {
include $config_dir . '/memcache.inc.php';
}
// Check memcache
if ($memcacheD) {
$key = 'thread_cache_load-' . $group;
if ($headers = unserialize($memcacheD->get($key))) {
if ($headers['memcache_time'] >= filemtime($spooldir . '/' . $group . '-lastupdate.dat')) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Using $key from memcache", FILE_APPEND);
}
return $headers;
}
}
}
$database = $spooldir . '/' . $group . '-data.db3';
$table = "threads";
if ($dbh = threads_db_open($database, $table)) {
@ -79,6 +94,18 @@ function thread_cache_load($group)
}
$dbh = null;
}
if ($memcacheD) {
$nicole = $memcacheD->delete($key);
$headers['memcache_time'] = time();
$memcacheD->add($key, serialize($headers), $memcache_ttl);
if ($enable_memcache_logging) {
if ($nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Updated $key in memcache", FILE_APPEND);
} else {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Wrote $key to memcache", FILE_APPEND);
}
}
}
return ($headers);
}
@ -191,7 +218,7 @@ function thread_overview_interpret($line, $overviewformat, $groupname)
for ($i = 0; $i < count($overviewfmt) - 1; $i ++) {
if ($overviewfmt[$i] == "Subject:") {
$subject = preg_replace('/\[doctalk\]/i', '', headerDecode($over[$i + 1]));
// $article->isReply = splitSubject($subject);
// $article->isReply = splitSubject($subject);
$article->subject = $subject;
}
if ($overviewfmt[$i] == "Date:") {
@ -692,12 +719,12 @@ function thread_format_subject($c, $group, $highlightids = false)
$offset = $CONFIG['timezone'] * 60;
}
/*
if ($c->isReply) {
$re = "Re: ";
} else {
$re = "";
}
*/
* if ($c->isReply) {
* $re = "Re: ";
* } else {
* $re = "";
* }
*/
$re = "";
// is the current article to be highlighted?
if ((is_array($highlightids))) {

View File

@ -643,14 +643,6 @@ function groups_show($gruppen)
$found = 1;
}
} else {
$result = $memcacheD->delete($lar_memcache);
if ($enable_memcache_logging) {
if ($result) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Deleted $lar_memcache from memcache", FILE_APPEND);
} else {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Failed to delete (or not found) $lar_memcache from memcache", FILE_APPEND);
}
}
unset($lastarticleinfo);
}
}
@ -659,12 +651,15 @@ function groups_show($gruppen)
$database = $spooldir . '/articles-overview.db3';
$table = 'overview';
$overview_dbh = overview_db_open($database);
$overview_query = $overview_dbh->prepare('SELECT * FROM overview WHERE newsgroup=:newsgroup ORDER BY CAST(date AS int) DESC LIMIT 2');
$overview_query = $overview_dbh->prepare('SELECT * FROM overview WHERE newsgroup=:newsgroup ORDER BY CAST(date AS int) DESC LIMIT 5');
$overview_query->execute([
'newsgroup' => $g->name
]);
$found = 0;
while ($row = $overview_query->fetch()) {
if($row['date'] > time()) {
continue;
}
$found = 1;
break;
}
@ -674,9 +669,13 @@ function groups_show($gruppen)
$lastarticleinfo = $row;
if ($memcacheD) {
touch($groupfile, $lastarticleinfo['date']);
$memcacheD->delete($lar_memcache);
$nicole = $memcacheD->delete($lar_memcache);
$memcacheD->add($lar_memcache, serialize($row), $memcache_ttl);
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Wrote $lar_memcache to memcache", FILE_APPEND);
if ($nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Updated $lar_memcache in memcache", FILE_APPEND);
} else {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Wrote $lar_memcache to memcache", FILE_APPEND);
}
}
}
}
@ -2345,6 +2344,12 @@ function insert_article_from_array($this_article, $check_duplicates = true)
}
}
if($this_article['epochdate'] > time()) {
echo "\n(newsportal)Article date in future. Skipping: " . $group . ":" . $this_article['mid'];
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Article date in future. Skipping: " . $group . ":" . $this_article['mid'], FILE_APPEND);
return "441 Insert failed (article date in future)\r\n";
}
// Open articles Database
if ($CONFIG['article_database'] == '1') {
$article_dbh = article_db_open($spooldir . '/' . $group . '-articles.db3');
@ -2407,7 +2412,11 @@ function insert_article_from_array($this_article, $check_duplicates = true)
$statusdate = time();
$statusreason = "imported";
add_to_history($group, $this_article['local'], $this_article['mid'], $status, $statusdate, $statusreason, $statusnotes);
touch($spooldir . '/' . $group . '-lastupdate.dat', $this_article['epochdate']);
if ($this_article['epochdate'] < time()) {
touch($spooldir . '/' . $group . '-lastupdate.dat', $this_article['epochdate']);
} else {
touch($spooldir . '/' . $group . '-lastupdate.dat', time());
}
}
function is_deleted_post($group, $number)

View File

@ -11,7 +11,7 @@ if(!$enable_memcache) {
$server = '127.0.0.1';
$port = 11211;
// Log all hits
// Log all hits (log file may be large)
$enable_memcache_logging = false;
// Time in seconds to cache data