Deploying to gh-pages from @ 7eda0defc233e850ec179bc95878b5403c3af855 🚀

This commit is contained in:
realaravinth
2023-11-04 19:26:59 +00:00
parent 5e41045795
commit d4e11fb15a
238 changed files with 1775 additions and 1070 deletions

View File

@@ -1288,6 +1288,64 @@
<a href="#1288" id="1288">1288</a>
<a href="#1289" id="1289">1289</a>
<a href="#1290" id="1290">1290</a>
<a href="#1291" id="1291">1291</a>
<a href="#1292" id="1292">1292</a>
<a href="#1293" id="1293">1293</a>
<a href="#1294" id="1294">1294</a>
<a href="#1295" id="1295">1295</a>
<a href="#1296" id="1296">1296</a>
<a href="#1297" id="1297">1297</a>
<a href="#1298" id="1298">1298</a>
<a href="#1299" id="1299">1299</a>
<a href="#1300" id="1300">1300</a>
<a href="#1301" id="1301">1301</a>
<a href="#1302" id="1302">1302</a>
<a href="#1303" id="1303">1303</a>
<a href="#1304" id="1304">1304</a>
<a href="#1305" id="1305">1305</a>
<a href="#1306" id="1306">1306</a>
<a href="#1307" id="1307">1307</a>
<a href="#1308" id="1308">1308</a>
<a href="#1309" id="1309">1309</a>
<a href="#1310" id="1310">1310</a>
<a href="#1311" id="1311">1311</a>
<a href="#1312" id="1312">1312</a>
<a href="#1313" id="1313">1313</a>
<a href="#1314" id="1314">1314</a>
<a href="#1315" id="1315">1315</a>
<a href="#1316" id="1316">1316</a>
<a href="#1317" id="1317">1317</a>
<a href="#1318" id="1318">1318</a>
<a href="#1319" id="1319">1319</a>
<a href="#1320" id="1320">1320</a>
<a href="#1321" id="1321">1321</a>
<a href="#1322" id="1322">1322</a>
<a href="#1323" id="1323">1323</a>
<a href="#1324" id="1324">1324</a>
<a href="#1325" id="1325">1325</a>
<a href="#1326" id="1326">1326</a>
<a href="#1327" id="1327">1327</a>
<a href="#1328" id="1328">1328</a>
<a href="#1329" id="1329">1329</a>
<a href="#1330" id="1330">1330</a>
<a href="#1331" id="1331">1331</a>
<a href="#1332" id="1332">1332</a>
<a href="#1333" id="1333">1333</a>
<a href="#1334" id="1334">1334</a>
<a href="#1335" id="1335">1335</a>
<a href="#1336" id="1336">1336</a>
<a href="#1337" id="1337">1337</a>
<a href="#1338" id="1338">1338</a>
<a href="#1339" id="1339">1339</a>
<a href="#1340" id="1340">1340</a>
<a href="#1341" id="1341">1341</a>
<a href="#1342" id="1342">1342</a>
<a href="#1343" id="1343">1343</a>
<a href="#1344" id="1344">1344</a>
<a href="#1345" id="1345">1345</a>
<a href="#1346" id="1346">1346</a>
<a href="#1347" id="1347">1347</a>
<a href="#1348" id="1348">1348</a>
</pre></div><pre class="rust"><code><span class="comment">// Copyright (C) 2022 Aravinth Manivannan &lt;realaravinth@batsense.net&gt;
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan &lt;realaravinth@batsense.net&gt;
//
@@ -2509,6 +2567,64 @@
<span class="prelude-val">Ok</span>(res.nonce <span class="kw">as </span>u32)
}
}
<span class="doccomment">/// Get number of analytics entries that are under a certain duration
</span><span class="kw">async fn </span>stats_get_num_logs_under_time(<span class="kw-2">&amp;</span><span class="self">self</span>, duration: u32) -&gt; DBResult&lt;usize&gt; {
<span class="kw">struct </span>Count {
count: <span class="prelude-ty">Option</span>&lt;i64&gt;,
}
<span class="comment">//&quot;SELECT COUNT(*) FROM (SELECT difficulty_factor FROM mcaptcha_pow_analytics WHERE time &lt;= ?) as count&quot;,
</span><span class="kw">let </span>count = <span class="macro">sqlx::query_as!</span>(
Count,
<span class="string">&quot;SELECT
COUNT(difficulty_factor) AS count
FROM
mcaptcha_pow_analytics
WHERE time &lt;= ?;&quot;</span>,
duration <span class="kw">as </span>i32,
)
.fetch_one(<span class="kw-2">&amp;</span><span class="self">self</span>.pool)
.<span class="kw">await
</span>.map_err(|e| map_row_not_found_err(e, DBError::CaptchaNotFound))<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(count.count.unwrap_or_else(|| <span class="number">0</span>) <span class="kw">as </span>usize)
}
<span class="doccomment">/// Get the entry at a location in the list of analytics entires under a certain time limited
/// and sorted in ascending order
</span><span class="kw">async fn </span>stats_get_entry_at_location_for_time_limit_asc(<span class="kw-2">&amp;</span><span class="self">self</span>, duration: u32, location: u32) -&gt; DBResult&lt;<span class="prelude-ty">Option</span>&lt;usize&gt;&gt; {
<span class="kw">struct </span>Difficulty {
difficulty_factor: <span class="prelude-ty">Option</span>&lt;i32&gt;,
}
<span class="kw">match </span><span class="macro">sqlx::query_as!</span>(
Difficulty,
<span class="string">&quot;SELECT
difficulty_factor
FROM
mcaptcha_pow_analytics
WHERE
time &lt;= ?
ORDER BY difficulty_factor ASC LIMIT 1 OFFSET ?;&quot;</span>,
duration <span class="kw">as </span>i32,
location <span class="kw">as </span>i64 - <span class="number">1</span>,
)
.fetch_one(<span class="kw-2">&amp;</span><span class="self">self</span>.pool)
.<span class="kw">await
</span>{
<span class="prelude-val">Ok</span>(res) =&gt; <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(res.difficulty_factor.unwrap() <span class="kw">as </span>usize)),
<span class="prelude-val">Err</span>(sqlx::Error::RowNotFound) =&gt; <span class="prelude-val">Ok</span>(<span class="prelude-val">None</span>),
<span class="prelude-val">Err</span>(e) =&gt; <span class="prelude-val">Err</span>(map_row_not_found_err(e, DBError::CaptchaNotFound))
}
}
}
<span class="attr">#[derive(Clone)]