/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to classes/cache/cachedb.php

  • Committer: Suren A. Chilingaryan
  • Date: 2018-03-23 03:25:36 UTC
  • Revision ID: csa@suren.me-20180323032536-r3nofczubbjlgmdv
Group INSERTs into the transactions for better INNODB performance

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 const NEED_REQUESTS = 0x00020000;      // Create appropriate requests on listing
24
24
 const FIND_BROKEN = 0x00040000;        // Find incomplete caches
25
25
 
 
26
 const INSERT_CALL = 1; 
 
27
 const DESTRUCTOR_CALL = 2;
 
28
 const START_CALL = 4;
 
29
 const INTERNAL_CALL = 7;
 
30
 
26
31
 function __construct(SOURCERequest $props = NULL) {
27
32
    parent::__construct();
28
33
    
62
67
 
63
68
 function __destruct() {
64
69
    if ($this->transaction_active) {
65
 
        $this->Commit();
 
70
        $this->Commit(CACHEDB::DESTRUCTOR_CALL);
66
71
    }
67
72
 
68
73
/*
1054
1059
 }
1055
1060
 
1056
1061
 function Insert($resolution, &$query) {
1057
 
    global $ADEI_MAX_OPERATIONS_PER_TRANSACTION;
 
1062
    global $ADEI_CONTINUOUS_TRANSACTION;
 
1063
    global $ADEI_TRANSACTION_SIZE;
1058
1064
    
1059
1065
    if (($this instanceof CACHE) == false)
1060
1066
        throw new ADEIException(translate("CreateTable calls are only allowed on CACHE object"));
1061
1067
    
1062
 
    if ($this->transaction_active)
1063
 
        $this->transaction_operations++;
 
1068
    if ($this->transaction_active) {
 
1069
        $this->transaction_operations++;
 
1070
    } else if ($ADEI_CONTINUOUS_TRANSACTION) {
 
1071
        $this->StartTransaction(CACHEDB::INSERT_CALL);
 
1072
        $this->transaction_operations++;
 
1073
    }
1064
1074
 
1065
 
    if ($this->transaction_operations > $ADEI_MAX_OPERATIONS_PER_TRANSACTION) {
1066
 
        $this->Commit();
1067
 
        $this->StartTransaction();
 
1075
    if ($this->transaction_operations > $ADEI_TRANSACTION_SIZE) {
 
1076
        $this->Commit(CACHEDB::INSERT_CALL);
 
1077
        $this->StartTransaction(CACHEDB::INSERT_CALL);
1068
1078
    }
1069
1079
 
1070
1080
    if (!@mysql_query($query, $this->dbh)) {
1100
1110
    return 0;
1101
1111
 }
1102
1112
 
1103
 
 function StartTransaction() {
1104
 
    global $ADEI_MAX_OPERATIONS_PER_TRANSACTION;
1105
 
    if (!$ADEI_MAX_OPERATIONS_PER_TRANSACTION) return;
 
1113
 function StartTransaction($flags = 0) {
 
1114
    global $ADEI_CONTINUOUS_TRANSACTION;
 
1115
    global $ADEI_TRANSACTION_SIZE;
 
1116
 
 
1117
    if (!$ADEI_TRANSACTION_SIZE) return;
 
1118
    if (($ADEI_CONTINUOUS_TRANSACTION)&&(($flags&CACHEDB::INTERNAL_CALL)==0)) return;
1106
1119
 
1107
1120
    if ($this->transaction_active) {
1108
 
        $this->Commit();
 
1121
        $this->Commit(CACHEDB::START_CALL);
1109
1122
    }
1110
1123
    if (@mysql_query("START TRANSACTION")) {
1111
1124
        $this->transaction_operations = 0;
1113
1126
    }
1114
1127
 }
1115
1128
 
1116
 
 function Commit() {
1117
 
    if (@mysql_query("COMMIT"))
1118
 
        throw new ADEIException(translate("Can't commit last transaction of %u operations", $this->transaction_operations));
1119
 
 
1120
 
    $this->transaction_active = false;
 
1129
 function Commit($flags = 0) {
 
1130
    global $ADEI_CONTINUOUS_TRANSACTION;
 
1131
    if (($ADEI_CONTINUOUS_TRANSACTION)&&(($flags&CACHEDB::INTERNAL_CALL)==0)) return;
 
1132
 
 
1133
    if ($this->transaction_active) {
 
1134
        echo "Commiting {$this->transaction_operations} operations as requested by {$flags}\n";
 
1135
        if (!@mysql_query("COMMIT"))
 
1136
            throw new ADEIException(translate("Can't commit last transaction of %u operations,  error %u: %s", $this->transaction_operations, mysql_errno($this->dbh), mysql_error($this->dbh)));
 
1137
 
 
1138
        $this->transaction_active = false;
 
1139
    }
1121
1140
 }
1122
1141
 
1123
1142