Batch watchlist status checks to eliminate rate limit errors
This commit is contained in:
parent
cdcaa245d1
commit
41e895d254
2 changed files with 65 additions and 32 deletions
|
|
@ -23635,6 +23635,27 @@ def check_watchlist_status():
|
||||||
print(f"Error checking watchlist status: {e}")
|
print(f"Error checking watchlist status: {e}")
|
||||||
return jsonify({"success": False, "error": str(e)}), 500
|
return jsonify({"success": False, "error": str(e)}), 500
|
||||||
|
|
||||||
|
@app.route('/api/watchlist/check-batch', methods=['POST'])
|
||||||
|
def check_watchlist_status_batch():
|
||||||
|
"""Check watchlist status for multiple artists in one request"""
|
||||||
|
try:
|
||||||
|
data = request.get_json()
|
||||||
|
artist_ids = data.get('artist_ids', [])
|
||||||
|
if not artist_ids:
|
||||||
|
return jsonify({"success": False, "error": "Missing artist_ids"}), 400
|
||||||
|
|
||||||
|
database = get_database()
|
||||||
|
pid = get_current_profile_id()
|
||||||
|
results = {}
|
||||||
|
for aid in artist_ids:
|
||||||
|
results[aid] = database.is_artist_in_watchlist(aid, profile_id=pid)
|
||||||
|
|
||||||
|
return jsonify({"success": True, "results": results})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error batch checking watchlist status: {e}")
|
||||||
|
return jsonify({"success": False, "error": str(e)}), 500
|
||||||
|
|
||||||
@app.route('/api/watchlist/scan', methods=['POST'])
|
@app.route('/api/watchlist/scan', methods=['POST'])
|
||||||
def start_watchlist_scan():
|
def start_watchlist_scan():
|
||||||
"""Start a watchlist scan for new releases"""
|
"""Start a watchlist scan for new releases"""
|
||||||
|
|
|
||||||
|
|
@ -28047,37 +28047,44 @@ async function updateWatchlistButtonCount() {
|
||||||
*/
|
*/
|
||||||
async function updateArtistCardWatchlistStatus() {
|
async function updateArtistCardWatchlistStatus() {
|
||||||
const artistCards = document.querySelectorAll('.artist-card');
|
const artistCards = document.querySelectorAll('.artist-card');
|
||||||
|
const artistIds = [];
|
||||||
for (const card of artistCards) {
|
for (const card of artistCards) {
|
||||||
const artistId = card.dataset.artistId;
|
const artistId = card.dataset.artistId;
|
||||||
if (!artistId) continue;
|
if (artistId) artistIds.push(artistId);
|
||||||
|
}
|
||||||
|
if (!artistIds.length) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/watchlist/check', {
|
const response = await fetch('/api/watchlist/check-batch', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ artist_id: artistId })
|
body: JSON.stringify({ artist_ids: artistIds })
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
if (data.success && data.results) {
|
||||||
|
for (const card of artistCards) {
|
||||||
|
const artistId = card.dataset.artistId;
|
||||||
|
if (!artistId) continue;
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
if (data.success) {
|
|
||||||
const button = card.querySelector('.watchlist-toggle-btn');
|
const button = card.querySelector('.watchlist-toggle-btn');
|
||||||
|
if (!button) continue;
|
||||||
const icon = button.querySelector('.watchlist-icon');
|
const icon = button.querySelector('.watchlist-icon');
|
||||||
const text = button.querySelector('.watchlist-text');
|
const text = button.querySelector('.watchlist-text');
|
||||||
|
|
||||||
if (data.is_watching) {
|
if (data.results[artistId]) {
|
||||||
icon.textContent = '👁️';
|
if (icon) icon.textContent = '👁️';
|
||||||
text.textContent = 'Watching...';
|
if (text) text.textContent = 'Watching...';
|
||||||
button.classList.add('watching');
|
button.classList.add('watching');
|
||||||
} else {
|
} else {
|
||||||
icon.textContent = '👁️';
|
if (icon) icon.textContent = '👁️';
|
||||||
text.textContent = 'Add to Watchlist';
|
if (text) text.textContent = 'Add to Watchlist';
|
||||||
button.classList.remove('watching');
|
button.classList.remove('watching');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error checking watchlist status for artist ${artistId}:`, error);
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error batch checking watchlist status:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36478,24 +36485,29 @@ async function toggleRecommendedWatchlist(btn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkRecommendedWatchlistStatuses(artists) {
|
async function checkRecommendedWatchlistStatuses(artists) {
|
||||||
for (const artist of artists) {
|
try {
|
||||||
try {
|
const artistIds = artists.map(a => a.artist_id).filter(Boolean);
|
||||||
const resp = await fetch('/api/watchlist/check', {
|
if (!artistIds.length) return;
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
const resp = await fetch('/api/watchlist/check-batch', {
|
||||||
body: JSON.stringify({ artist_id: artist.artist_id })
|
method: 'POST',
|
||||||
});
|
headers: { 'Content-Type': 'application/json' },
|
||||||
const data = await resp.json();
|
body: JSON.stringify({ artist_ids: artistIds })
|
||||||
if (data.success && data.is_watching) {
|
});
|
||||||
const btn = document.querySelector(`.recommended-card-watchlist-btn[data-artist-id="${artist.artist_id}"]`);
|
const data = await resp.json();
|
||||||
if (btn) {
|
if (data.success && data.results) {
|
||||||
btn.classList.add('watching');
|
for (const [aid, isWatching] of Object.entries(data.results)) {
|
||||||
btn.textContent = 'Watching';
|
if (isWatching) {
|
||||||
|
const btn = document.querySelector(`.recommended-card-watchlist-btn[data-artist-id="${aid}"]`);
|
||||||
|
if (btn) {
|
||||||
|
btn.classList.add('watching');
|
||||||
|
btn.textContent = 'Watching';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
// Non-critical
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Non-critical
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue