Skip to content

Commit

Permalink
Unify the logic for requesting sync
Browse files Browse the repository at this point in the history
  • Loading branch information
odisseus committed Dec 12, 2024
1 parent 4199ef9 commit 3cc920f
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public interface SyncRequester {
private static class QueueingSyncRequester implements SyncRequester {
private final Project project;

private final AtomicBoolean changePending = new AtomicBoolean(false);
private final ConcurrentLinkedQueue<VirtualFile> unprocessedChanges = new ConcurrentLinkedQueue<>();

public QueueingSyncRequester(Project project) {
Expand All @@ -192,9 +191,7 @@ public void afterQuerySync(Project project, BlazeContext context) {
if (!requester.project.equals(project)) {
return;
}
if (requester.changePending.get()) {
requester.requestSyncInternal(ImmutableList.of());
}
requester.requestSync(ImmutableList.of());
}
},
parentDisposable);
Expand All @@ -206,8 +203,9 @@ public void requestSync(@NotNull Collection<VirtualFile> files) {
logger.info(String.format("Putting %d files into sync queue", files.size()));
ImmutableList<VirtualFile> changesToProcess = ImmutableList.of();
synchronized (unprocessedChanges) {
// TODO aggregate multiple events into one sync request
unprocessedChanges.addAll(files);
if (changePending.compareAndSet(false, true)) {
if (!unprocessedChanges.isEmpty()) {
if (!BlazeSyncStatus.getInstance(project).syncInProgress()) {
changesToProcess = ImmutableList.copyOf(unprocessedChanges);
unprocessedChanges.clear();
Expand All @@ -220,12 +218,11 @@ public void requestSync(@NotNull Collection<VirtualFile> files) {
}

private void requestSyncInternal(ImmutableCollection<VirtualFile> files) {
logger.info(String.format("Requesting sync of %d files", files.size()));
logger.info(String.format("Requesting sync of files: %s", files));
QuerySyncManager.getInstance(project)
.deltaSync(
QuerySyncActionStatsScope.createForFiles(QuerySyncAsyncFileListener.class, null, files),
TaskOrigin.AUTOMATIC);
changePending.set(false);
}
}

Expand Down

0 comments on commit 3cc920f

Please sign in to comment.