-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_api_check.js
More file actions
44 lines (38 loc) · 1.87 KB
/
Copy pathdebug_api_check.js
File metadata and controls
44 lines (38 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import axios from 'axios';
const BASE_URL = 'https://api.mcsrranked.com';
const NICKNAME = 'pinamejeff';
const BATCH_SIZE = 5;
async function main() {
console.log('=== FINAL ISOLATION TEST (Fixed) ===\n');
const t0 = Date.now();
// Step 1: Both initial calls in parallel
const [statsRes, firstMatchRes] = await Promise.all([
axios.get(`${BASE_URL}/users/${NICKNAME}`),
axios.get(`${BASE_URL}/users/${NICKNAME}/matches?count=1`)
]);
const stats = statsRes.data.data;
const season = firstMatchRes.data.data[0]?.season;
const totalCount = stats?.statistics?.season?.playedMatches?.ranked || 50;
console.log(`Season: ${season}, Total ranked: ${totalCount} [${Date.now() - t0}ms]`);
// Step 2: Single request capped at 100
const t1 = Date.now();
const count = Math.min(totalCount, 100);
const sumRes = await axios.get(`${BASE_URL}/users/${NICKNAME}/matches?count=${count}`);
const summaries = (sumRes.data.data || []).filter(m => m.season === season);
console.log(`Summaries (${summaries.length} matches) fetched in ${Date.now() - t1}ms`);
// Step 3: Batch detail fetches
const ids = summaries.map(m => m.id);
console.log(`\nFetching ${ids.length} match details in batches of ${BATCH_SIZE}...`);
const t2 = Date.now();
let fetched = 0;
for (let i = 0; i < ids.length; i += BATCH_SIZE) {
const chunk = ids.slice(i, i + BATCH_SIZE);
await Promise.allSettled(chunk.map(id => axios.get(`${BASE_URL}/matches/${id}`)));
fetched += chunk.length;
process.stdout.write(`\r ${fetched}/${ids.length} details`);
}
console.log(`\nAll details fetched in ${((Date.now() - t2) / 1000).toFixed(1)}s`);
console.log(`\nTOTAL LOAD TIME: ${((Date.now() - t0) / 1000).toFixed(1)}s`);
console.log('(Subsequent loads will use cache — nearly instant)');
}
main().catch(console.error);