tangled
alpha
login
or
join now
dunkirk.sh
/
bunplayground
1
fork
atom
random bun scripts that dont fit anywhere else
1
fork
atom
overview
issues
pulls
pipelines
feat: add cache
dunkirk.sh
10 months ago
e075dd2d
fa98587c
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+75
-1
1 changed file
expand all
collapse all
unified
split
bluesky-community-verifications.js
+75
-1
bluesky-community-verifications.js
···
8
8
// Mark script as initialized
9
9
window.bskyTrustedUsersInitialized = true;
10
10
11
11
-
// Define a storage key for trusted users
11
11
+
// Define storage keys
12
12
const TRUSTED_USERS_STORAGE_KEY = "bsky_trusted_users";
13
13
+
const VERIFICATION_CACHE_STORAGE_KEY = "bsky_verification_cache";
14
14
+
const CACHE_EXPIRY_TIME = 24 * 60 * 60 * 1000; // 24 hours
13
15
14
16
// Function to get trusted users from local storage
15
17
const getTrustedUsers = () => {
···
38
40
saveTrustedUsers(updatedUsers);
39
41
};
40
42
43
43
+
// Cache functions
44
44
+
const getVerificationCache = () => {
45
45
+
const cache = localStorage.getItem(VERIFICATION_CACHE_STORAGE_KEY);
46
46
+
return cache ? JSON.parse(cache) : {};
47
47
+
};
48
48
+
49
49
+
const saveVerificationCache = (cache) => {
50
50
+
localStorage.setItem(VERIFICATION_CACHE_STORAGE_KEY, JSON.stringify(cache));
51
51
+
};
52
52
+
53
53
+
const getCachedVerifications = (user) => {
54
54
+
const cache = getVerificationCache();
55
55
+
return cache[user] || null;
56
56
+
};
57
57
+
58
58
+
const cacheVerifications = (user, records) => {
59
59
+
const cache = getVerificationCache();
60
60
+
cache[user] = {
61
61
+
records,
62
62
+
timestamp: Date.now(),
63
63
+
};
64
64
+
saveVerificationCache(cache);
65
65
+
};
66
66
+
67
67
+
const isCacheValid = (cacheEntry) => {
68
68
+
return cacheEntry && Date.now() - cacheEntry.timestamp < CACHE_EXPIRY_TIME;
69
69
+
};
70
70
+
71
71
+
const clearCache = () => {
72
72
+
localStorage.removeItem(VERIFICATION_CACHE_STORAGE_KEY);
73
73
+
console.log("Verification cache cleared");
74
74
+
};
75
75
+
41
76
// Store all verifiers for a profile
42
77
let profileVerifiers = [];
43
78
···
62
97
try {
63
98
// Helper function to fetch all verification records with pagination
64
99
const fetchAllVerifications = async (user) => {
100
100
+
// Check cache first
101
101
+
const cachedData = getCachedVerifications(user);
102
102
+
if (cachedData && isCacheValid(cachedData)) {
103
103
+
console.log(`Using cached verification data for ${user}`);
104
104
+
return cachedData.records;
105
105
+
}
106
106
+
107
107
+
console.log(`Fetching fresh verification data for ${user}`);
65
108
let allRecords = [];
66
109
let cursor = null;
67
110
let hasMore = true;
···
85
128
}
86
129
}
87
130
131
131
+
// Save to cache
132
132
+
cacheVerifications(user, allRecords);
88
133
return allRecords;
89
134
};
90
135
···
466
511
padding-top: 15px;
467
512
`;
468
513
514
514
+
// Create cache control buttons
515
515
+
const cacheControls = document.createElement("div");
516
516
+
cacheControls.style.cssText = `
517
517
+
margin-top: 15px;
518
518
+
padding-top: 15px;
519
519
+
border-top: 1px solid #eee;
520
520
+
`;
521
521
+
522
522
+
const clearCacheButton = document.createElement("button");
523
523
+
clearCacheButton.textContent = "Clear Verification Cache";
524
524
+
clearCacheButton.style.cssText = `
525
525
+
padding: 8px 15px;
526
526
+
background-color: #735A5A;
527
527
+
color: white;
528
528
+
border: none;
529
529
+
border-radius: 4px;
530
530
+
cursor: pointer;
531
531
+
margin-right: 10px;
532
532
+
`;
533
533
+
clearCacheButton.addEventListener("click", () => {
534
534
+
clearCache();
535
535
+
alert(
536
536
+
"Verification cache cleared. Fresh data will be fetched on next check.",
537
537
+
);
538
538
+
});
539
539
+
540
540
+
cacheControls.appendChild(clearCacheButton);
541
541
+
469
542
// Create close button
470
543
const closeButton = document.createElement("button");
471
544
closeButton.textContent = "Close";
···
482
555
modalContent.appendChild(modalHeader);
483
556
modalContent.appendChild(form);
484
557
modalContent.appendChild(trustedUsersList);
558
558
+
modalContent.appendChild(cacheControls);
485
559
modalContent.appendChild(closeButton);
486
560
settingsModal.appendChild(modalContent);
487
561