Ignore:
Timestamp:
May 2, 2014, 9:45:06 AM (10 years ago)
Author:
plg
Message:

huge speed improvement: use a dedicated short-term visit log instead of history table

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AntiAspi/maintain.inc.php

    r3609 r28323  
    11<?php
    2 
    32if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    43
    5 function plugin_install()
     4class AntiAspi_maintain extends PluginMaintain
    65{
    7   global $prefixeTable;
     6  private $installed = false;
    87
    9   $query = 'SHOW TABLES LIKE "' . $prefixeTable . 'antiaspi_ip_ban"';
    10   $result = pwg_query($query);
    11   if (!mysql_fetch_row($result))
     8  function __construct($plugin_id)
    129  {
    13     $q = "CREATE TABLE " . $prefixeTable . "antiaspi_ip_ban (
    14       id int(11) NOT NULL auto_increment,
    15       ip char(50) NOT NULL default '',
    16       date char(20) NOT NULL default '',
    17       PRIMARY KEY (id),
    18       KEY ip (ip))
    19     DEFAULT CHARACTER SET utf8";
    20     pwg_query($q);
     10    parent::__construct($plugin_id);
     11  }
     12
     13  function install($plugin_version, &$errors=array())
     14  {
     15    global $prefixeTable;
     16
     17    // table antiaspi_ip_ban to store list of banned IP addresses
     18    $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'antiaspi_ip_ban";');
     19    if (!pwg_db_num_rows($result))
     20    {
     21      $query = "
     22CREATE TABLE " . $prefixeTable . "antiaspi_ip_ban (
     23  id int(11) NOT NULL auto_increment,
     24  ip char(50) NOT NULL default '',
     25  date char(20) NOT NULL default '',
     26  PRIMARY KEY (id),
     27  KEY ip (ip)
     28) ENGINE=MyISAM DEFAULT CHARSET=utf8
     29;";
     30      pwg_query($query);
     31    }
     32
     33    // table antiaspi_log to store a specific "short-term" log
     34    // (ENGINE=MEMORY, specific)
     35    $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'antiaspi_log";');
     36    if (!pwg_db_num_rows($result))
     37    {
     38      $query = "
     39CREATE TABLE " . $prefixeTable . "antiaspi_log (
     40  IP varchar(15) NOT NULL default '',
     41  occured_on datetime NOT NULL,
     42  image_id mediumint(8) default NULL,
     43  category_id smallint(5) default NULL
     44) ENGINE=MEMORY DEFAULT CHARSET=utf8
     45;";
     46      pwg_query($query);
     47    }
     48
     49    $this->installed = true;
     50  }
     51
     52  function activate($plugin_version, &$errors=array())
     53  {
     54    if (!$this->installed)
     55    {
     56      $this->install($plugin_version, $errors);
     57    }
     58  }
     59
     60  function deactivate()
     61  {
     62  }
     63
     64  function uninstall()
     65  {
     66    global $prefixeTable;
     67
     68    pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_ip_ban;');
     69    pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_log;');
    2170  }
    2271}
    23 
    24 function plugin_uninstall()
    25 {
    26   global $prefixeTable;
    27 
    28         $q = 'DROP TABLE ' . $prefixeTable . 'antiaspi_ip_ban;';
    29   pwg_query($q);
    30 }
    31 
    3272?>
Note: See TracChangeset for help on using the changeset viewer.