VASTLY decreased the amount of pregenerations done by the site, greatly improving performance

This commit is contained in:
bingus_violet 2024-06-25 01:32:39 -05:00
parent ae1397d84a
commit ba79d970a1
3 changed files with 11 additions and 3 deletions

1
api.js
View file

@ -56,6 +56,7 @@ function socketeer() {
module.exports.connected = true module.exports.connected = true
ping(30000) ping(30000)
lastPong = Date.now() lastPong = Date.now()
events.emit("lanyardConnect")
} else if (data.op == 3) { } else if (data.op == 3) {
lastPong = Date.now() lastPong = Date.now()
} else if (data.op == 0) { } else if (data.op == 0) {

View file

@ -20,6 +20,7 @@ var globalSpins = 0
var commitCount = "500+" var commitCount = "500+"
var uptime = Date.now() var uptime = Date.now()
var lastPregen = 0
var pregenFiles = [] var pregenFiles = []
@ -231,6 +232,7 @@ function converter(html, dynamic = true) {
"LAST_LANYARD": timeFormatter((Date.now() - api.lastLanyardUpdate) / 1000), "LAST_LANYARD": timeFormatter((Date.now() - api.lastLanyardUpdate) / 1000),
"RANDOM_TITLE": titles[Math.floor(Math.random() * titles.length)], "RANDOM_TITLE": titles[Math.floor(Math.random() * titles.length)],
"RANDOM_QUOTE": quotes[Math.floor(Math.random() * quotes.length)], "RANDOM_QUOTE": quotes[Math.floor(Math.random() * quotes.length)],
"LAST_PREGEN": timeFormatter((Date.now() - lastPregen) / 1000)
} }
if (dynamic) { if (dynamic) {
@ -353,6 +355,7 @@ updateCommits()
function pregenerate() { function pregenerate() {
lastPregen = Date.now()
for (var i = 0; i < pregenFiles.length; i++) { for (var i = 0; i < pregenFiles.length; i++) {
var startTime = Date.now() var startTime = Date.now()
pregenFiles[i].html = converter(fs.readFileSync(pregenFiles[i].absolutePath).toString(), false) pregenFiles[i].html = converter(fs.readFileSync(pregenFiles[i].absolutePath).toString(), false)
@ -362,8 +365,12 @@ function pregenerate() {
pregenerate() pregenerate()
api.events.on("lanyardConnect", pregenerate)
api.events.on("lanyardUpdate", async () => { api.events.on("lanyardUpdate", async () => {
if (!api.lanyard.activityChanged) {
pregenerate() pregenerate()
}
for (var i = 0; i < api.lanyard.activities.length; i++) { for (var i = 0; i < api.lanyard.activities.length; i++) {
var activity = api.lanyard.activities[i] var activity = api.lanyard.activities[i]

View file

@ -45,7 +45,7 @@
</div> </div>
</div> </div>
</div> </div>
<p class="noscript">Violet has been spun {SPINCOUNT} times!</p> <!-- <p class="noscript">Violet has been spun {SPINCOUNT} times!</p> -->
<p class="spinnyCount" style="display: none;">You have spun Violet <span class="localSpins">4</span> times!<br> <p class="spinnyCount" style="display: none;">You have spun Violet <span class="localSpins">4</span> times!<br>
Everyone has spun Violet <span class="globalSpins">{SPINCOUNT}</span> times!</p> Everyone has spun Violet <span class="globalSpins">{SPINCOUNT}</span> times!</p>