Skip to content

Commit

Permalink
GH-236: fix cache state
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Lisenkov <[email protected]>
  • Loading branch information
dnlsv committed Feb 19, 2025
1 parent 2866c9d commit ec48245
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ interface FileFetchProvider<R : Any, Q : Query<R, Unit>, File : VirtualFile> {

fun isCacheValid(query: Q): Boolean

fun markCacheAsFetching(query: Q)

fun isCacheFetching(query: Q): Boolean

fun getFetchedErrorMessage(query: Q): String? = "Error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ abstract class RemoteFileFetchProviderBase<Connection : ConnectionConfigBase, Re
return lock.withLock { cacheState[query] != CacheState.ERROR }
}

/**
* Sets cache state to [CacheState.FETCHING] for the specified query.
* @param query query that identifies the cache.
*/
override fun markCacheAsFetching(query: RemoteQuery<Connection, Request, Unit>) {
lock.withLock { cacheState[query] = CacheState.FETCHING }
}

/**
* Checks if the cache is fetching.
* @param query query that identifies the cache.
* @return true if fetching is in progress, false if not.
*/
override fun isCacheFetching(query: RemoteQuery<Connection, Request, Unit>): Boolean {
return lock.withLock { cacheState[query] == CacheState.FETCHING }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ abstract class FileFetchNode<Connection : ConnectionConfigBase, Value : Any, R :
}
} else {
if (!fileFetchProvider.isCacheFetching(q)) {
fileFetchProvider.markCacheAsFetching(q)
runBackgroundableSyncTask(
title = makeFetchTaskTitle(q),
project = project,
Expand Down

0 comments on commit ec48245

Please sign in to comment.