[repo] Make time from event to push 5x shorter by using folder size checking
This commit is contained in:
parent
1f18a8c984
commit
fa3997beff
|
@ -34,11 +34,12 @@ namespace SparkleLib {
|
||||||
private Timer RemoteTimer;
|
private Timer RemoteTimer;
|
||||||
private Timer LocalTimer;
|
private Timer LocalTimer;
|
||||||
private FileSystemWatcher Watcher;
|
private FileSystemWatcher Watcher;
|
||||||
private bool HasChanged;
|
|
||||||
private DateTime LastChange;
|
|
||||||
private System.Object ChangeLock;
|
private System.Object ChangeLock;
|
||||||
private int FetchRequests;
|
private int FetchRequests;
|
||||||
private SparkleListener Listener;
|
private SparkleListener Listener;
|
||||||
|
private bool HasChanged;
|
||||||
|
private List <double> SizeBuffer;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The folder name the repository resides in locally
|
/// The folder name the repository resides in locally
|
||||||
|
@ -391,10 +392,12 @@ namespace SparkleLib {
|
||||||
Listener.ListenForChanges ();
|
Listener.ListenForChanges ();
|
||||||
|
|
||||||
|
|
||||||
|
SizeBuffer = new List <double> ();
|
||||||
|
|
||||||
// Keep a timer that checks if there are changes and
|
// Keep a timer that checks if there are changes and
|
||||||
// whether they have settled
|
// whether they have settled
|
||||||
LocalTimer = new Timer () {
|
LocalTimer = new Timer () {
|
||||||
Interval = 4000
|
Interval = 250
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
|
LocalTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
|
||||||
|
@ -442,6 +445,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
|
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
git.WaitForExit ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,14 +457,17 @@ namespace SparkleLib {
|
||||||
|
|
||||||
if (HasChanged) {
|
if (HasChanged) {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes found, checking if settled.");
|
if (SizeBuffer.Count >= 4)
|
||||||
|
SizeBuffer.RemoveAt (0);
|
||||||
|
|
||||||
DateTime now = DateTime.UtcNow;
|
DirectoryInfo dir_info = new DirectoryInfo (LocalPath);
|
||||||
TimeSpan changed = new TimeSpan (now.Ticks - LastChange.Ticks);
|
SizeBuffer.Add (CalculateFolderSize (dir_info));
|
||||||
|
|
||||||
if (changed.TotalMilliseconds > 5000) {
|
if (SizeBuffer [0].Equals (SizeBuffer [1]) &&
|
||||||
|
SizeBuffer [1].Equals (SizeBuffer [2]) &&
|
||||||
|
SizeBuffer [2].Equals (SizeBuffer [3])) {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes have settled, adding files...");
|
SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes have settled.");
|
||||||
|
|
||||||
_IsBuffering = false;
|
_IsBuffering = false;
|
||||||
|
|
||||||
|
@ -502,12 +509,12 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + fse_args.Name + "'");
|
SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + fse_args.Name + "'");
|
||||||
|
SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes found, checking if settled.");
|
||||||
|
|
||||||
RemoteTimer.Stop ();
|
RemoteTimer.Stop ();
|
||||||
|
|
||||||
lock (ChangeLock) {
|
lock (ChangeLock) {
|
||||||
|
|
||||||
LastChange = DateTime.UtcNow;
|
|
||||||
HasChanged = true;
|
HasChanged = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -705,7 +712,9 @@ namespace SparkleLib {
|
||||||
git.Exited += delegate {
|
git.Exited += delegate {
|
||||||
|
|
||||||
if (Status.MergeConflict.Count > 0) {
|
if (Status.MergeConflict.Count > 0) {
|
||||||
Console.WriteLine ("CONFLICT");
|
|
||||||
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict detected...");
|
||||||
|
|
||||||
foreach (string problem_file_name in Status.MergeConflict) {
|
foreach (string problem_file_name in Status.MergeConflict) {
|
||||||
|
|
||||||
SparkleGit git_ours = new SparkleGit (LocalPath,
|
SparkleGit git_ours = new SparkleGit (LocalPath,
|
||||||
|
@ -868,6 +877,37 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Recursively gets a folder's size in bytes
|
||||||
|
private double CalculateFolderSize (DirectoryInfo parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!System.IO.Directory.Exists (parent.ToString ()))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
double size = 0;
|
||||||
|
|
||||||
|
// Ignore the temporary 'rebase-apply' directory. This prevents potential
|
||||||
|
// crashes when files are being queried whilst the files have already been deleted.
|
||||||
|
if (parent.Name.Equals ("rebase-apply"))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
foreach (FileInfo file in parent.GetFiles()) {
|
||||||
|
|
||||||
|
if (!file.Exists)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
size += file.Length;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (DirectoryInfo directory in parent.GetDirectories())
|
||||||
|
size += CalculateFolderSize (directory);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create a first commit in case the user has cloned
|
// Create a first commit in case the user has cloned
|
||||||
// an empty repository
|
// an empty repository
|
||||||
private void CreateInitialCommit ()
|
private void CreateInitialCommit ()
|
||||||
|
|
Loading…
Reference in a new issue