Skip to content

Commit

Permalink
Add Clear Stat Cache dev button
Browse files Browse the repository at this point in the history
  • Loading branch information
SeinopSys committed Aug 14, 2019
1 parent 85c09dc commit f9081f5
Show file tree
Hide file tree
Showing 28 changed files with 281 additions and 260 deletions.
18 changes: 8 additions & 10 deletions app/Controllers/AdminController.php
@@ -1,33 +1,23 @@
<?php

namespace App\Controllers;
use App\Appearances;
use App\Auth;
use App\CoreUtils;
use App\CSRFProtection;
use App\DB;
use App\Input;
use App\JSON;
use App\Logs;
use App\Models\Appearance;
use App\Models\DiscordMember;
use App\Models\Logs\Log;
use App\Models\Notice;
use App\Models\Post;
use App\Models\UsefulLink;
use App\Models\User;
use App\Models\UserPref;
use App\Pagination;
use App\Permission;
use App\PostgresDbWrapper;
use App\Posts;
use App\RegExp;
use App\Response;
use App\UserPrefs;
use App\Users;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
use IPTools\IP;
use RestCord\DiscordClient;

class AdminController extends Controller {
public $do = 'admin';
Expand Down Expand Up @@ -557,4 +547,12 @@ public function noticesApi($params){
CoreUtils::notAllowed();
}
}

public function statCacheApi() {
if ($this->action !== 'DELETE')
CoreUtils::notAllowed();

clearstatcache();
Response::done();
}
}
2 changes: 2 additions & 0 deletions app/Controllers/DiscordAuthController.php
Expand Up @@ -130,6 +130,8 @@ private function _setTarget($params){
}

public function sync($params){
Response::fail('The Discord account link got severed, you will need to re-link your account.', ['segway' => true]);

$this->_setTarget($params);

$discordUser = $this->_target->discord_member;
Expand Down
8 changes: 4 additions & 4 deletions app/Models/Post.php
Expand Up @@ -128,7 +128,7 @@ public function get_approval_entry(){
FROM log__post_lock pl
LEFT JOIN log l ON l.reftype = 'post_lock' AND l.refid = pl.entryid
WHERE $where_query
ORDER BY pl.entryid ASC
ORDER BY pl.entryid
LIMIT 1", $where_bind
);
}
Expand Down Expand Up @@ -327,9 +327,9 @@ public function getLi(bool $view_only = false, bool $cachebust_url = false, bool
$HTML .= $post_label.$posted_at.$post_type.$reserved_at.$finished_at.$locked_at;

if (!empty($this->fullsize))
$HTML .= "<span class='info-line'><a href='{$this->fullsize}' class='original color-green' target='_blank' rel='noopener'><span class='typcn typcn-link'></span> Original image</a></span>";
$HTML .= "<span class='info-line'><a href='{$this->fullsize}' class='original' target='_blank' rel='noopener'><span class='typcn typcn-link'></span> Original image</a></span>";
if (!$approved && Permission::sufficient('staff'))
$HTML .= "<span class='info-line'><a href='{$this->reserver->getOpenSubmissionsURL()}' class='color-blue' target='_blank' rel='noopener'><span class='typcn typcn-arrow-forward'></span> View open submissions</a></span>";
$HTML .= "<span class='info-line'><a href='{$this->reserver->getOpenSubmissionsURL()}' target='_blank' rel='noopener'><span class='typcn typcn-arrow-forward'></span> View open submissions</a></span>";
}
else $HTML .= $post_label.$posted_at.$reserved_at;
}
Expand Down Expand Up @@ -403,7 +403,7 @@ public function getActionsHTML($view_only, bool $hide_reserver_status, bool $ena
}
if (!empty($Buttons)){
if ($view_only !== false)
$HTML .= "<div><a href='$view_only' class='btn blue typcn typcn-arrow-forward'>View</a></div>";
$HTML .= "<div><a href='$view_only' class='btn link typcn typcn-arrow-forward'>View</a></div>";
else {
$regularButton = \count($Buttons) < 3;
foreach ($Buttons as $b){
Expand Down
12 changes: 6 additions & 6 deletions assets/js/global.jsx
Expand Up @@ -163,7 +163,7 @@
}
if (!cdExists || diff.past){
clearCD();
$.API.get('/about/upcoming', $.mkAjaxHandler(function(){
$.API.get('/about/upcoming', function(){
if (!this.status) return console.error(`Failed to load upcoming event list: ${this.message}`);

const $uc = $('#upcoming');
Expand All @@ -172,7 +172,7 @@
$uc.addClass('hidden');
else $uc.removeClass('hidden');
window.setUpcomingCountdown();
}));
});
return;
}
let text;
Expand Down Expand Up @@ -540,11 +540,11 @@

$.Dialog.wait(title,'Signing out');

$.API.post('/da-auth/sign-out',$.mkAjaxHandler(function(){
$.API.post('/da-auth/sign-out', function(){
if (!this.status) return $.Dialog.fail(title,this.message);

$.Navigation.reload();
}));
});
});
});

Expand All @@ -556,7 +556,7 @@
if ($sessionUpdating === null)
return;

$.API.get('/da-auth/status', $.mkAjaxHandler(function(){
$.API.get('/da-auth/status', function(){
if ($sessionUpdating === null)
return;

Expand All @@ -568,7 +568,7 @@
if (this.deleted === true)
$.Dialog.fail(sessionRefTitle, "We couldn't refresh your DeviantArt session automatically so you have been signed out. Due to elements on the page assuming you are signed in some actions will not work as expected until the page is reloaded.");
$sessionUpdating.html(this.loggedIn).removeClass('updating-session');
}));
});
}, pollInterval);
}

Expand Down
4 changes: 2 additions & 2 deletions assets/js/jquery.ponycolorpalette.js
Expand Up @@ -43,13 +43,13 @@

waitingList[this.appearanceId] = [this];

$.API.post(`/cg/appearance/${this.appearanceId}/link-targets?hex`, $.mkAjaxHandler(data => {
$.API.post(`/cg/appearance/${this.appearanceId}/link-targets?hex`, data => {
if (!data.status) return this.displayError(data.message);

$.each(waitingList[this.appearanceId], (_, picker) => {
picker.fillSwatchBox(data.list);
});
}));
});
}
fillSwatchBox(list){
this.$swatchBox.removeClass('loading').children().first().nextAll().remove();
Expand Down
22 changes: 18 additions & 4 deletions assets/js/pages/admin/index.js
Expand Up @@ -80,7 +80,7 @@

const ids = deviationIDArray.join(',');

$.API.post('/admin/mass-approve', { ids }, $.mkAjaxHandler(function(){
$.API.post('/admin/mass-approve', { ids }, function(){
if (!this.status) return $.Dialog.fail(false, this.message);

if (this.html){
Expand All @@ -91,10 +91,24 @@
if (this.message)
$.Dialog.success(false, this.message, true);
else $.Dialog.close();
}));
});
}
})();

$('#clear-stat-cache').on('click', e => {
e.preventDefault();

$.Dialog.wait('Clearing file stat cache');

$.API.delete('/admin/stat-cache', function () {
if (!this.status) return $.Dialog.fail(false, this.message);

if (this.message)
$.Dialog.success(false, this.message, true);
else $.Dialog.close();
});
});

const deviationIO = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (!entry.isIntersecting)
Expand All @@ -107,13 +121,13 @@
postID = el.dataset.postId,
viewonly = el.dataset.viewonly;

$.API.get(`/post/${postID}/lazyload`,{viewonly},$.mkAjaxHandler(function(){
$.API.get(`/post/${postID}/lazyload`,{viewonly},function(){
if (!this.status) return $.Dialog.fail(`Cannot load post ${postID}`, this.message);

$.loadImages(this.html).then(function(resp){
$(el).closest('.image').replaceWith(resp.$el);
});
}));
});
});
});
const imageIO = new IntersectionObserver(entries => {
Expand Down
4 changes: 2 additions & 2 deletions assets/js/pages/admin/log.js
Expand Up @@ -32,7 +32,7 @@
$this.addClass('typcn-times color-red').css('cursor','not-allowed').off('click');
};

$.API.get(`/admin/logs/details/${EntryID}`,$.mkAjaxHandler(function(){
$.API.get(`/admin/logs/details/${EntryID}`, function(){
if (!this.status){
if (this.unclickable === true)
$this.replaceWith($this.text().trim());
Expand Down Expand Up @@ -61,7 +61,7 @@
$dataDiv.insertAfter($this).slideDown();
Time.update();
$this.addClass('typcn-minus color-darkblue');
})).always(function(){
}).always(function(){
requesting = false;
$this.removeClass('typcn-refresh');
}).fail(fail);
Expand Down
12 changes: 6 additions & 6 deletions assets/js/pages/admin/useful-links.js
Expand Up @@ -13,7 +13,7 @@

$.Dialog.wait(`Editing link #${linkid}`, 'Retrieving link information from server');

$.API.get(`/admin/usefullinks/${linkid}`,$.mkAjaxHandler(function(){
$.API.get(`/admin/usefullinks/${linkid}`, function(){
if (!this.status) return $.Dialog.fail(false, this.message);

let data = this;
Expand All @@ -23,7 +23,7 @@
$form.find('input[name=title]').val(data.title);
$form.find('select[name=minrole]').val(data.minrole);
});
}));
});
});
$uflol.on('click','.delete-link',function(){
let $li = $(this).closest('[id^=ufl-]'),
Expand All @@ -34,15 +34,15 @@

$.Dialog.wait(false, 'Removing link');

$.API.delete(`/admin/usefullinks/${linkId}`,$.mkAjaxHandler(function(){
$.API.delete(`/admin/usefullinks/${linkId}`, function(){
if (!this.status) return $.Dialog.fail(false, this.message);

$li.remove();
$('#ufl-link-'+linkId).remove();
if ($sbUflContainer.is(':empty'))
$sbUflContainer.hide();
$.Dialog.close();
}));
});
});
});
$('#add-link').on('click',function(){
Expand Down Expand Up @@ -113,11 +113,11 @@
list.push($(this).find('.typcn-arrow-move').remove().end().attr('id').split('-').pop());
});

$.API.post('/admin/usefullinks/reorder', {list:list.join(',')}, $.mkAjaxHandler(function(){
$.API.post('/admin/usefullinks/reorder', {list:list.join(',')}, function(){
if (!this.status) return $.Dialog.fail(false, this.message);

$.Navigation.reload(true);
}));
});
}
});
})();
4 changes: 2 additions & 2 deletions assets/js/pages/admin/wsdiag.js
Expand Up @@ -131,7 +131,7 @@
$.Dialog.success(false, 'Hello response received', true);
});

$.API.get('/admin/wsdiag/hello', { priv, clientid }, $.mkAjaxHandler(function(){
$.API.get('/admin/wsdiag/hello', { priv, clientid }, function(){
if (!this.status) return $.Dialog.fail(false, this.message);

if (!responseReceived)
Expand All @@ -146,6 +146,6 @@
$w.off('ws-hello');
$.Dialog.fail(false, 'Hello response timed out');
}, timeout);
}));
});
});
})();
4 changes: 2 additions & 2 deletions assets/js/pages/colorguide/full-list.js
Expand Up @@ -84,15 +84,15 @@
if (EQG)
data.eqg = true;

$.API.post('/cg/full/reorder', data, $.mkAjaxHandler(function(){
$.API.post('/cg/full/reorder', data, function(){
if (!this.status) return $.Dialog.fail(false, this.message);

$fullList.removeClass('sorting').html(this.html);
reobserve();
$ReorderBtn.removeClass('typcn-tick green').addClass('typcn-arrow-unsorted darkblue').html('Re-order');
$ReorderCancelBtn.addClass('hidden');
$.Dialog.close();
}));
});
}
});

Expand Down
4 changes: 2 additions & 2 deletions assets/js/pages/colorguide/guide.js
Expand Up @@ -151,9 +151,9 @@
source: (q, callback) => {
if (appearanceAutocompleteCache.has(q))
return callback(appearanceAutocompleteCache.get(q));
$.API.get(`/cg/appearances`, { q, EQG }, $.mkAjaxHandler(data => {
$.API.get(`/cg/appearances`, { q, EQG }, data => {
callback(appearanceAutocompleteCache.set(q, data));
}));
});
},
templates: {
header: () => `<div class="aa-header">
Expand Down

0 comments on commit f9081f5

Please sign in to comment.