xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit 49acbf556027578733ed631c551b6cb3266d2af6

Drop old and empty slave tables
Author: Catalin(ux) M. BOIE
Author date (UTC): 2015-12-30 09:00
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2015-12-30 09:05
Parent(s): 9c1328fa3c207d9bc109c2dd486999318a215d84
Signing key:
Tree: 0bb1f83f13f7c3521c133e4368056e088e7f81fe
File Lines added Lines deleted
scripts/cron.php 51 4
File scripts/cron.php changed (mode: 100644) (index 76d38eb..db7cc6a)
... ... if (gmdate("Hi") == "0105") {
149 149 } }
150 150
151 151 if (gmdate("Hi") == "0300") { if (gmdate("Hi") == "0300") {
152 rg_log("Clean old forget_pass entries...");
152 rg_log_enter("Clean old forget_pass entries...");
153 153 $sql = "DELETE FROM forgot_pass WHERE expire < $now"; $sql = "DELETE FROM forgot_pass WHERE expire < $now";
154 154 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
155 155 rg_sql_free_result($res); rg_sql_free_result($res);
156 rg_log_exit();
156 157 } }
157 158
158 159 if (gmdate("i") == "30") { if (gmdate("i") == "30") {
159 rg_log("Clean old tokens...");
160 rg_log_enter("Clean old tokens...");
160 161 $sql = "DELETE FROM tokens WHERE expire < $now"; $sql = "DELETE FROM tokens WHERE expire < $now";
161 162 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
162 163 rg_sql_free_result($res); rg_sql_free_result($res);
164 rg_log_exit();
163 165 } }
164 166
165 167 if (gmdate("i") == "01") { if (gmdate("i") == "01") {
166 rg_log("Clean old sess entries...");
168 rg_log_enter("Clean old sess entries...");
167 169 $sql = "DELETE FROM sess WHERE expire < $now"; $sql = "DELETE FROM sess WHERE expire < $now";
168 170 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
169 171 rg_sql_free_result($res); rg_sql_free_result($res);
172 rg_log_exit();
170 173 } }
171 174
172 175 if (gmdate("Hi") == "0605") { if (gmdate("Hi") == "0605") {
173 rg_log("Clean old login_tokens_ip entries...");
176 rg_log_enter("Clean old login_tokens_ip entries...");
174 177 $sql = "DELETE FROM login_tokens_ip WHERE expire < $now"; $sql = "DELETE FROM login_tokens_ip WHERE expire < $now";
175 178 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
176 179 rg_sql_free_result($res); rg_sql_free_result($res);
180 rg_log_exit();
181 }
182
183 if (gmdate("dHi") == "010610") {
184 rg_log_enter("Clean old empty slave tables...");
185
186 $ts = time() - 3 * 31 * 24 * 3600;
187 $limit = gmdate('Y_m', $ts);
188 rg_log('limit=' . $limit);
189 foreach ($rg_sql_struct_slaves as $table) {
190 rg_log('Slave: ' . $table);
191 $sql = 'SELECT relname FROM pg_class'
192 . ' WHERE relname LIKE \'' . $table . '_%\''
193 . ' AND relkind = \'r\''
194 . ' AND relname < \'' . $table . '_' . $limit . '\''
195 . ' ORDER BY relname';
196 $res = rg_sql_query($db, $sql);
197 if ($res === FALSE) {
198 rg_log('Cannot load slave tables: ' . rg_sql_error());
199 break;
200 }
201 while (($row = rg_sql_fetch_array($res))) {
202 $sql = 'SELECT 1 FROM ' . $row['relname'] . ' LIMIT 1';
203 $res2 = rg_sql_query($db, $sql);
204 if ($res2 === FALSE) {
205 rg_log('Cannot select from table ['
206 . $row['relname'] . ']: '
207 . rg_sql_error());
208 break;
209 }
210 $rows = rg_sql_num_rows($res2);
211 rg_sql_free_result($res2);
212
213 if ($rows == 1)
214 continue;
215
216 $sql = 'DROP TABLE ' . $row['relname'];
217 $res2 = rg_sql_query($db, $sql);
218 rg_sql_free_result($res2);
219 }
220 rg_sql_free_result($res);
221 }
222
223 rg_log_exit();
177 224 } }
178 225
179 226 rg_log_cron(); rg_log_cron();
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master