def Refresh(key, limits):
		# Limits is in format [(timespan, max-count),...]
		# The windows are anchored at midnight
		# The timespan is used to uniquely identify limit instances between runs
		midnight = datetime.combine(datetime.utcnow().date(), datetime.min.time())
		time_since_midnight = (midnight - datetime.utcnow())

		rl_db.limits.remove({"Key": key, "Expires": {"$lt": datetime.utcnow()}})
		current_limits = list(rl_db.limits.with_options(read_preference=ReadPreference.PRIMARY).find({"Key": key}, {"Duration": 1}))
		missing_limits = [x for x in limits if x[0].total_seconds() not in [limit["Duration"] for limit in current_limits]]
		for limit in missing_limits:
			window_start = midnight + timedelta(seconds=math.floor(time_since_midnight.total_seconds()/limit[0].total_seconds()) * limit[0].total_seconds())
			window_end = window_start + limit[0]
			rl_db.limits.insert({"Key": key, "Count": 0, "Duration": limit[0].total_seconds(), "Max": limit[1], "Expires": window_end})
dataset/ETHPy150Open cpfair/tapiriik/tapiriik/services/ratelimiting.py/RateLimit.Refresh/swapped operands of `-`