mirror of
https://github.com/madari-media/madari-oss.git
synced 2026-05-18 23:21:50 +00:00
fix: trakt integration calling too many apis
Some checks are pending
Build and Deploy / build_windows (push) Waiting to run
Build and Deploy / build_android (push) Waiting to run
Build and Deploy / build_android_tv (push) Waiting to run
Build and Deploy / build_ipa (push) Waiting to run
Build and Deploy / build_linux (push) Waiting to run
Build and Deploy / build_macos (push) Waiting to run
Some checks are pending
Build and Deploy / build_windows (push) Waiting to run
Build and Deploy / build_android (push) Waiting to run
Build and Deploy / build_android_tv (push) Waiting to run
Build and Deploy / build_ipa (push) Waiting to run
Build and Deploy / build_linux (push) Waiting to run
Build and Deploy / build_macos (push) Waiting to run
This commit is contained in:
parent
91e0968cd8
commit
fbea109161
3 changed files with 50 additions and 39 deletions
|
|
@ -156,9 +156,11 @@ class TraktContainerState extends State<TraktContainer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
_logger.info('Refreshing data');
|
try {
|
||||||
_cachedItems = [];
|
_logger.info('Refreshing data for ${widget.loadId}');
|
||||||
await _loadData();
|
_cachedItems = [];
|
||||||
|
await _loadData();
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
String get title {
|
String get title {
|
||||||
|
|
@ -234,7 +236,7 @@ class TraktContainerState extends State<TraktContainer> {
|
||||||
),
|
),
|
||||||
Stack(
|
Stack(
|
||||||
children: [
|
children: [
|
||||||
if ((_cachedItems ?? []).isEmpty && !_isLoading)
|
if ((_cachedItems ?? []).isEmpty && !_isLoading && _error != null)
|
||||||
const Positioned.fill(
|
const Positioned.fill(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text("Nothing to see here"),
|
child: Text("Nothing to see here"),
|
||||||
|
|
@ -242,18 +244,46 @@ class TraktContainerState extends State<TraktContainer> {
|
||||||
),
|
),
|
||||||
if (_isLoading && (_cachedItems ?? []).isEmpty)
|
if (_isLoading && (_cachedItems ?? []).isEmpty)
|
||||||
const SpinnerCards(),
|
const SpinnerCards(),
|
||||||
SizedBox(
|
if (_error != null) Text(_error!),
|
||||||
height: getListHeight(context),
|
if (_error != null)
|
||||||
child: RenderListItems(
|
Positioned.fill(
|
||||||
isWide: widget.loadId == "up_next_series",
|
child: Center(
|
||||||
items: _cachedItems ?? [],
|
child: Column(
|
||||||
error: _error,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
itemScrollController: _scrollController,
|
children: [
|
||||||
hasError: _error != null,
|
Text(
|
||||||
heroPrefix: "trakt_up_next${widget.loadId}",
|
"Error: $_error",
|
||||||
service: TraktService.stremioService!,
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: Colors.red,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_error = null;
|
||||||
|
});
|
||||||
|
_loadData();
|
||||||
|
},
|
||||||
|
child: const Text("Retry"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (_error == null)
|
||||||
|
SizedBox(
|
||||||
|
height: getListHeight(context),
|
||||||
|
child: RenderListItems(
|
||||||
|
isWide: widget.loadId == "up_next_series",
|
||||||
|
items: _cachedItems ?? [],
|
||||||
|
error: _error,
|
||||||
|
itemScrollController: _scrollController,
|
||||||
|
hasError: _error != null,
|
||||||
|
heroPrefix: "trakt_up_next${widget.loadId}",
|
||||||
|
service: TraktService.stremioService!,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ class TraktService {
|
||||||
|
|
||||||
final refetchKey = BehaviorSubject<List<String>>();
|
final refetchKey = BehaviorSubject<List<String>>();
|
||||||
|
|
||||||
static const Duration _cacheRevalidationInterval = Duration(hours: 1);
|
|
||||||
|
|
||||||
static TraktService? _instance;
|
static TraktService? _instance;
|
||||||
static TraktService? get instance => _instance;
|
static TraktService? get instance => _instance;
|
||||||
static BaseConnectionService? stremioService;
|
static BaseConnectionService? stremioService;
|
||||||
|
|
@ -43,8 +41,6 @@ class TraktService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer? _cacheRevalidationTimer;
|
|
||||||
|
|
||||||
clearCache() {
|
clearCache() {
|
||||||
_logger.info('Clearing cache');
|
_logger.info('Clearing cache');
|
||||||
_cache.clear();
|
_cache.clear();
|
||||||
|
|
@ -132,25 +128,6 @@ class TraktService {
|
||||||
|
|
||||||
void _startCacheRevalidation() {
|
void _startCacheRevalidation() {
|
||||||
_logger.info('Starting cache revalidation timer');
|
_logger.info('Starting cache revalidation timer');
|
||||||
_cacheRevalidationTimer = Timer.periodic(
|
|
||||||
_cacheRevalidationInterval,
|
|
||||||
(_) async {
|
|
||||||
await _revalidateCache();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _revalidateCache() async {
|
|
||||||
_logger.info('Revalidating cache');
|
|
||||||
for (final key in _cache.keys) {
|
|
||||||
final cachedData = _cache[key];
|
|
||||||
if (cachedData != null) {
|
|
||||||
final updatedData = await _makeRequest(key, bypassCache: true);
|
|
||||||
_cache[key] = updatedData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
saveCacheToDisk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> _makeRequest(String url, {bool bypassCache = false}) async {
|
Future<dynamic> _makeRequest(String url, {bool bypassCache = false}) async {
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,11 @@ class _HomeTabPageState extends State<HomeTabPage> {
|
||||||
|
|
||||||
if (state == null) continue;
|
if (state == null) continue;
|
||||||
|
|
||||||
promises.add(state.refresh());
|
promises.add(() async {
|
||||||
|
try {
|
||||||
|
state.refresh();
|
||||||
|
} catch (e) {}
|
||||||
|
}());
|
||||||
}
|
}
|
||||||
|
|
||||||
await Future.wait(promises);
|
await Future.wait(promises);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue