Permalink
Browse files

Fix external DB performance issue

  • Loading branch information...
0bitus committed Aug 4, 2017
1 parent f4beb54 commit 0ab0afbc65ea52e28ce0b682e23bf5a572df7883
Showing with 22 additions and 9 deletions.
  1. +1 −1 admin/cron/cron_user.phpsh
  2. +1 −1 classes/class.Pagination.php
  3. +18 −5 classes/class.Subscription.php
  4. +1 −1 l10n/EN.php
  5. +1 −1 layout/template/notification.tpl
@@ -1,4 +1,4 @@
#! /usr/bin/env php
#! /usr/bin/php -q
<?php
/**
* @author Alexander Rein <a.rein@be-clever-ag.de>, beclever werbeagentur AG <support@be-clever-ag.de>
@@ -46,7 +46,7 @@ public function getPart($limit = 100, $page = 1) {
return $result;
}
public function createLinks($links = 7, $list_class = "pagination") {
public function createLinks($links = 5, $list_class = "pagination") {
if ($this->_limit == 'all' || $this->_total <= $this->_limit) {
return '';
}
@@ -65,6 +65,7 @@ public function add_subscription($user, $duration, $kID = "") {
} else {
$key = empty($kID) ? $user : "#{$kID}";
$return = $this->db->fetch_array_assoc();
$this->sync_external_user_table($return["sID"]);
$this->log("User #{$this->uID} create subscription #{$return["sID"]} (Key: '{$key}')");
return $return;
}
@@ -97,7 +98,6 @@ public function get_subscription($sID = "") {
public function set_pass($sID, $pass) {
$password = crypt($pass, '$2y$10$' . PasswordGenerator::getAlphaNumericPassword(22));
$sql = "UPDATE subscription SET password = ? WHERE uID = ?";
$this->db->addParams("s", $password);
$this->db->addParams("i", $this->uID);
@@ -112,9 +112,7 @@ public function set_pass($sID, $pass) {
return FALSE;
} else {
if ($sID == "all") {
foreach ($this->get_sID() as $sub) {
$this->sync_external_user_table($sub["sID"]);
}
$this->sync_external_passwords($password);
} else {
$this->sync_external_user_table($sID);
}
@@ -151,7 +149,7 @@ public function get_all_subscription_user_info($active = TRUE) {
}
public function get_active_subscriptions($sID = "") {
$sql = "SELECT sID, uID, username, password, exp_time FROM subscription WHERE active = 1 AND exp_time > NOW() AND password IS NOT NULL AND status = " . self::STATUS_NONE;
$sql = "SELECT sID, uID, username, password, exp_time FROM subscription WHERE active = 1 AND exp_time > NOW() AND status = " . self::STATUS_NONE;
if (!empty($sID)) {
$this->db->addParams("i", $sID);
$sql .= " AND sID = ?";
@@ -320,6 +318,21 @@ private function sync_external_user_table_all() {
}
}
private function sync_external_passwords($pass) {
if (sync_external_db) {
$ext_db = new DBconn(ext_DB_host, ext_DB_user, ext_DB_pass, ext_DB_name, ext_DB_flag, ext_DB_ca);
$ext_db->addParams("s", $pass);
$ext_db->addParams("i", $this->uID);
$sql = "UPDATE user_auth SET password = ? WHERE user_ID = ?";
if ($ext_db->query($sql) === FALSE) {
$this->exception($ext_db->error);
return FALSE;
}
} else {
return TRUE;
}
}
private function create_external_table(&$ext_db) {
$sql = "CREATE TABLE IF NOT EXISTS `user_auth` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
@@ -263,7 +263,7 @@
$LOCAL["subscription"]["table_head"]["create_date"] = "Create Date";
$LOCAL["subscription"]["table_head"]["expire_date"] = "Expire Date";
$LOCAL["subscription"]["dialog"]["key"]["title"] = "Register subscription keys";
$LOCAL["subscription"]["dialog"]["key"]["label"] = "Subscription keys (one per line)";
$LOCAL["subscription"]["dialog"]["key"]["label"] = "Subscription keys (one per line, max 500)";
$LOCAL["subscription"]["dialog"]["key"]["submit"] = "Register keys";
$LOCAL["subscription"]["dialog"]["extend"]["title"] = "Extend subscription duration";
$LOCAL["subscription"]["dialog"]["extend"]["label_selected"] = "Selected subscriptions";
@@ -1,7 +1,7 @@
{extends file="layout/template/template.tpl"}
{block name=content}
<div class="grid50">
<div class="grid66">
<form method="post" action="process/user_update.php" class="ajax">
<input type="hidden" name="action" value="notification" />
<table class="ui-widget ui-widget-content table-form">

0 comments on commit 0ab0afb

Please sign in to comment.