Help with query timeout error

Hi,
I am more of a power user trying to develop, so your help is MUCH appreciated. Trying to learn as I go, hands on.
I create a JS custom button that triggers a python method that I have been tweaking in several ways (both using new_doc and db.sql), breaking it into two methods (one to get dates and the other to save as below), but once I get the code working, it runs great for a few records (adding 4-ish meeting dates). But when I need to create a longer list, I face a timeout issue.
Essentially, I want to schedule regular meetings between two user defined dates in the specified days of the week between these dates, always at the same (to and from) times.

Here is the code:

@frappe.whitelist()
	def get_meeting_dates(self):
		meeting_dates = []
		"""Returns a list of meeting dates and also creates a child document for each meeting date with meeting time"""     
		days_of_week = [self.monday, self.tuesday, self.wednesday, self.thursday, self.friday, self.saturday, self.sunday]
		current_date = datetime.strptime(self.c_datestart, "%Y-%m-%d")
		final_date = datetime.strptime(self.c_dateend, "%Y-%m-%d")
		while current_date <= final_date:
			if days_of_week[current_date.weekday()]:
				meeting_dates.append(current_date)
				current_date += timedelta(days=1)
		return meeting_dates
	
	
	@frappe.whitelist()
	def save_dates(self):
		"""Define variables"""
		meeting_dates = self.get_meeting_dates()
		from_time = self.from_time
		to_time = self.to_time
		cs = self.name
		pf = "cs_meetinfo"
		pt = "Course Schedule"
		
		# Clear existing meeting dates
		frappe.db.sql(
			"DELETE FROM `tabCourse Schedule Meeting Dates` WHERE parent=%s", self.name
		)
		print("Deleted existing meeting dates")

		# Create new meeting dates
						
		for date in meeting_dates:
			name= cs+"-"+str(date)
			frappe.db.sql(
				"INSERT INTO `tabCourse Schedule Meeting Dates` (name, parent, parentfield, parenttype, cs_meetdate, cs_fromtime, cs_totime) VALUES (%s, %s, %s, %s, %s, %s, %s)",
				(name, cs, pf, pt, date, from_time, to_time)
			)
		print(date)

Thanks so much for ANY help!

Solved. The issue was not writing to db, but creating the list itself.
The form had distinct checkboxes for the days of the week, so on the JS, I used

frm.add_custom_button(__('Add Meeting Dates'), function()  {
			const selectedDays = [];
  			if (frm.doc.monday) {
    			selectedDays.push("Monday")};
			if (frm.doc.tuesday) {
				selectedDays.push("Tuesday")};
			if (frm.doc.wednesday) {
				selectedDays.push("Wednesday")};
			if (frm.doc.thursday) {
				selectedDays.push("Thursday")};
			if (frm.doc.friday) {
				selectedDays.push("Friday")};
			if (frm.doc.saturday) {
				selectedDays.push("Saturday")};
			if (frm.doc.sunday) {
				selectedDays.push("Sunday")};

			frappe.dom.freeze(__("Scheduling..."));
			frm.call('schedule_dates', { days: selectedDays })

then on Py

@frappe.whitelist()
	def schedule_dates(self, days):
	# Clear existing meeting dates
		frappe.db.sql(
		"DELETE FROM `tabCourse Schedule Meeting Dates` WHERE parent=%s", self.name
			)
				
		"""Returns a list of meeting dates and also creates a child document for each meeting date with meeting time"""     
		meeting_dates = []
		meeting_dates_errors = []
		current_date = self.c_datestart
		
			
		while current_date <= self.c_dateend:
			if calendar.day_name[getdate(current_date).weekday()] in days:
				meeting_date = self.save_dates(current_date)
				try:
					meeting_date.save()
				except OverlapError:
					meeting_dates_errors.append(current_date)
				else:
					meeting_dates.append(meeting_date)
			current_date = add_days(current_date, 1)
		
		return dict(
			meeting_dates=meeting_dates,
			meeting_dates_errors=meeting_dates_errors,
				)