feat: implement cross-platform features and UI integration
- iOS: Add BackgroundSyncService, SyncScheduler, SyncWorker, BookmarkViewModel, FeedViewModel - iOS: Add BackgroundSyncService, SyncScheduler, SyncWorker services - Linux: Add settings-store.vala, State.vala signals, view widgets (FeedList, FeedDetail, AddFeed, Search, Settings, Bookmark) - Linux: Add bookmark-store.vala, bookmark vala model, search-service.vala - Android: Add NotificationService, NotificationManager, NotificationPreferencesStore - Android: Add BookmarkDao, BookmarkRepository, SettingsStore - Add unit tests for iOS, Android, Linux - Add integration tests - Add performance benchmarks - Update tasks and documentation Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -14,18 +14,39 @@ class SearchService(
|
||||
private val searchHistoryDao: SearchHistoryDao,
|
||||
private val resultProvider: SearchResultProvider
|
||||
) {
|
||||
private val cache = mutableMapOf<String, List<SearchResult>>()
|
||||
private data class CacheEntry(val results: List<SearchResult>, val timestamp: Long)
|
||||
private val cache = mutableMapOf<String, CacheEntry>()
|
||||
private val maxCacheSize = 100
|
||||
private val cacheExpirationMs = 5 * 60 * 1000L // 5 minutes
|
||||
|
||||
private fun isCacheEntryExpired(entry: CacheEntry): Boolean {
|
||||
return System.currentTimeMillis() - entry.timestamp > cacheExpirationMs
|
||||
}
|
||||
|
||||
private fun cleanExpiredCacheEntries() {
|
||||
cache.keys.removeAll { key ->
|
||||
cache[key]?.let { isCacheEntryExpired(it) } ?: false
|
||||
}
|
||||
}
|
||||
|
||||
fun search(query: String): Flow<List<SearchResult>> {
|
||||
val cacheKey = query.hashCode().toString()
|
||||
|
||||
// Return cached results if available
|
||||
cache[cacheKey]?.let { return flow { emit(it) } }
|
||||
// Clean expired entries periodically
|
||||
if (cache.size > maxCacheSize / 2) {
|
||||
cleanExpiredCacheEntries()
|
||||
}
|
||||
|
||||
// Return cached results if available and not expired
|
||||
cache[cacheKey]?.let { entry ->
|
||||
if (!isCacheEntryExpired(entry)) {
|
||||
return flow { emit(entry.results) }
|
||||
}
|
||||
}
|
||||
|
||||
return flow {
|
||||
val results = resultProvider.search(query)
|
||||
cache[cacheKey] = results
|
||||
cache[cacheKey] = CacheEntry(results, System.currentTimeMillis())
|
||||
if (cache.size > maxCacheSize) {
|
||||
cache.remove(cache.keys.first())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user