import db from './db'

/**
 * Gets a course from the database.
 *
 * @param {Number} clbid - a class/lab ID
 * @returns {Promise} - TreoDatabasePromise
 * @promise TreoDatabasePromise
 * @fulfill {Object} - the course object.
 * @reject {Error} - a message about retrieval failing.
 */
function getCourse(clbid) {
	// console.log('called getCourse', clbid)
	return db
		.store('courses')
		.index('clbid')
		.get(clbid)
		.catch(error => ({clbid, error}))
}

export default getCourse

@@ -16,16 +16,51 @@
 './db'%0A%0A
+const courseCache = new WeakMap()%0A%0A
 /**%0A * G
@@ -314,16 +314,37 @@
 ng.%0A */%0A
+export default async 
 function
@@ -410,21 +410,247 @@
 id)%0A
-%09return db%0A%09%09
+%0A%09if (courseCache.has(clbid)) %7B%0A%09%09let value = courseCache.get(clbid)%0A%09%09if (value instanceof Promise) %7B%0A%09%09%09return await value%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09return value%0A%09%09%7D%0A%09%09return courseCache.get(clbid)%0A%09%7D%0A%0A%09let course%0A%09try %7B%0A%09%09const coursePromise = db
 .sto
@@ -662,19 +662,16 @@
 ourses')
-%0A%09%09
 .index('
@@ -681,42 +681,120 @@
 id')
-%0A%09%09.get(clbid)%0A%09%09.
+.get(clbid)%0A%09%09courseCache.set(clbid, coursePromise)%0A%09%09course = await coursePromise%0A%09%7D%0A%09
 catch
+ 
 (error
- =%3E (
+) %7B%0A%09%09return 
 %7Bclb
@@ -807,35 +807,225 @@
 ror%7D
-))%0A%7D%0A%0Aexport default getCourse
+%0A%09%7D%0A%0A%09courseCache.set(clbid, course)%0A%0A%09return course%0A%7D%0A%0A// export default function getCourse(clbid) %7B%0A// %09return db%0A// %09%09.store('courses')%0A// %09%09.index('clbid')%0A// %09%09.get(clbid)%0A// %09%09.catch(error =%3E (%7Bclbid, error%7D))%0A// %7D
 %0A

add a courseCache to getCourse