mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
adding last saved course to try to reduces excessive file writes
This commit is contained in:
@@ -53,7 +53,7 @@ public class FileStorageTests
|
|||||||
Modules = []
|
Modules = []
|
||||||
};
|
};
|
||||||
|
|
||||||
await fileManager.SaveCourseAsync(testCourse);
|
await fileManager.SaveCourseAsync(testCourse, null);
|
||||||
|
|
||||||
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
||||||
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
||||||
@@ -76,7 +76,7 @@ public class FileStorageTests
|
|||||||
Modules = []
|
Modules = []
|
||||||
};
|
};
|
||||||
|
|
||||||
await fileManager.SaveCourseAsync(testCourse);
|
await fileManager.SaveCourseAsync(testCourse, null);
|
||||||
|
|
||||||
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
||||||
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
||||||
@@ -99,7 +99,7 @@ public class FileStorageTests
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
await fileManager.SaveCourseAsync(testCourse);
|
await fileManager.SaveCourseAsync(testCourse, null);
|
||||||
|
|
||||||
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
||||||
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
||||||
@@ -134,7 +134,7 @@ public class FileStorageTests
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
await fileManager.SaveCourseAsync(testCourse);
|
await fileManager.SaveCourseAsync(testCourse, null);
|
||||||
|
|
||||||
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
||||||
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
||||||
@@ -174,7 +174,7 @@ public class FileStorageTests
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
await fileManager.SaveCourseAsync(testCourse);
|
await fileManager.SaveCourseAsync(testCourse, null);
|
||||||
|
|
||||||
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
||||||
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
||||||
@@ -235,7 +235,7 @@ public class FileStorageTests
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
await fileManager.SaveCourseAsync(testCourse);
|
await fileManager.SaveCourseAsync(testCourse, null);
|
||||||
|
|
||||||
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
var loadedCourses = await fileManager.LoadSavedMarkdownCourses();
|
||||||
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
var loadedCourse = loadedCourses.First(c => c.Settings.Name == testCourse.Settings.Name);
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
DaysOfWeek = days,
|
DaysOfWeek = days,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await fileStorageManager.SaveCourseAsync(course);
|
await fileStorageManager.SaveCourseAsync(course, null);
|
||||||
NewFileCreated();
|
NewFileCreated();
|
||||||
}
|
}
|
||||||
await updateCourses();
|
await updateCourses();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class CoursePlanner
|
|||||||
private Timer? _debounceTimer;
|
private Timer? _debounceTimer;
|
||||||
private int _debounceInterval = 1000;
|
private int _debounceInterval = 1000;
|
||||||
private LocalCourse? _localCourse { get; set; }
|
private LocalCourse? _localCourse { get; set; }
|
||||||
|
private LocalCourse? _lastSavedCourse { get; set; }
|
||||||
public LocalCourse? LocalCourse
|
public LocalCourse? LocalCourse
|
||||||
{
|
{
|
||||||
get => _localCourse;
|
get => _localCourse;
|
||||||
@@ -61,12 +62,15 @@ public class CoursePlanner
|
|||||||
if (LocalCourse == null)
|
if (LocalCourse == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("saving course as of debounce call time");
|
Console.WriteLine("saving course as of debounce call time");
|
||||||
await fileStorageManager.SaveCourseAsync(courseAsOfDebounce);
|
await fileStorageManager.SaveCourseAsync(courseAsOfDebounce, null);
|
||||||
|
_lastSavedCourse = courseAsOfDebounce;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("Saving latest version of file");
|
Console.WriteLine("Saving latest version of file");
|
||||||
await fileStorageManager.SaveCourseAsync(LocalCourse);
|
var courseToSave = LocalCourse;
|
||||||
|
await fileStorageManager.SaveCourseAsync(courseToSave, _lastSavedCourse);
|
||||||
|
_lastSavedCourse = courseToSave;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ public class FileStorageManager
|
|||||||
this.logger.Log("Using storage directory: " + _basePath);
|
this.logger.Log("Using storage directory: " + _basePath);
|
||||||
|
|
||||||
}
|
}
|
||||||
public async Task SaveCourseAsync(LocalCourse course)
|
public async Task SaveCourseAsync(LocalCourse course, LocalCourse? previouslyStoredCourse)
|
||||||
{
|
{
|
||||||
await _saveMarkdownCourse.Save(course);
|
await _saveMarkdownCourse.Save(course, previouslyStoredCourse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class MarkdownCourseSaver
|
|||||||
_basePath = FileConfiguration.GetBasePath();
|
_basePath = FileConfiguration.GetBasePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Save(LocalCourse course)
|
public async Task Save(LocalCourse course, LocalCourse? previouslyStoredCourse)
|
||||||
{
|
{
|
||||||
var courseDirectory = $"{_basePath}/{course.Settings.Name}";
|
var courseDirectory = $"{_basePath}/{course.Settings.Name}";
|
||||||
if (!Directory.Exists(courseDirectory))
|
if (!Directory.Exists(courseDirectory))
|
||||||
@@ -103,6 +103,7 @@ public class MarkdownCourseSaver
|
|||||||
|
|
||||||
var filePath = assignmentsDirectory + "/" + assignment.Name + ".md";
|
var filePath = assignmentsDirectory + "/" + assignment.Name + ".md";
|
||||||
await File.WriteAllTextAsync(filePath, assignmentMarkdown);
|
await File.WriteAllTextAsync(filePath, assignmentMarkdown);
|
||||||
|
Console.WriteLine("saving file");
|
||||||
}
|
}
|
||||||
removeOldAssignments(assignmentsDirectory, module);
|
removeOldAssignments(assignmentsDirectory, module);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user