From cee696a4c8df6780554fc35b61262193a050c87c Mon Sep 17 00:00:00 2001
From: "Jonny_Bro (Nikita)" <48434875+JonnyBro@users.noreply.github.com>
Date: Thu, 3 Aug 2023 08:53:32 +0500
Subject: [PATCH] Cache couse when loaded from database

---
 .../gamemodes/beatrun/gamemode/cl/OnlineCourse.lua   | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/beatrun/gamemodes/beatrun/gamemode/cl/OnlineCourse.lua b/beatrun/gamemodes/beatrun/gamemode/cl/OnlineCourse.lua
index 541f651..67abd16 100644
--- a/beatrun/gamemodes/beatrun/gamemode/cl/OnlineCourse.lua
+++ b/beatrun/gamemodes/beatrun/gamemode/cl/OnlineCourse.lua
@@ -52,7 +52,17 @@ function GetCourse(sharecode)
 
 			PrintTable(headers)
 
-			LoadCourseRaw(util.Compress(body))
+			local dir = "beatrun/courses/" .. game.GetMap() .. "/"
+
+			file.CreateDir(dir)
+
+			local coursedata = util.Compress(body)
+
+			if not file.Exists(dir .. sharecode .. ".txt", "DATA") then
+				file.Write(dir .. sharecode .. ".txt", coursedata)
+			end
+
+			LoadCourseRaw(coursedata)
 
 			return true
 		else