Skip to content
Snippets Groups Projects
Commit e728798a authored by srosse's avatar srosse
Browse files

OO-990: use putIfAbsent to fill the course cache instead of doInSync

parent 344b0d45
No related branches found
No related tags found
No related merge requests found
...@@ -88,7 +88,6 @@ import org.olat.core.util.WebappHelper; ...@@ -88,7 +88,6 @@ import org.olat.core.util.WebappHelper;
import org.olat.core.util.ZipUtil; import org.olat.core.util.ZipUtil;
import org.olat.core.util.cache.CacheWrapper; import org.olat.core.util.cache.CacheWrapper;
import org.olat.core.util.coordinate.CoordinatorManager; import org.olat.core.util.coordinate.CoordinatorManager;
import org.olat.core.util.coordinate.SyncerCallback;
import org.olat.core.util.coordinate.SyncerExecutor; import org.olat.core.util.coordinate.SyncerExecutor;
import org.olat.core.util.event.MultiUserEvent; import org.olat.core.util.event.MultiUserEvent;
import org.olat.core.util.nodes.INode; import org.olat.core.util.nodes.INode;
...@@ -257,7 +256,7 @@ public class CourseFactory extends BasicManager { ...@@ -257,7 +256,7 @@ public class CourseFactory extends BasicManager {
public static ICourse createEmptyCourse(OLATResourceable ores, String shortTitle, String longTitle, String learningObjectives) { public static ICourse createEmptyCourse(OLATResourceable ores, String shortTitle, String longTitle, String learningObjectives) {
PersistingCourseImpl newCourse = new PersistingCourseImpl(ores.getResourceableId()); PersistingCourseImpl newCourse = new PersistingCourseImpl(ores.getResourceableId());
// Put new course in course cache // Put new course in course cache
putCourseInCache(newCourse.getResourceableId() ,newCourse); loadedCourses.put(newCourse.getResourceableId() ,newCourse);
Structure initialStructure = new Structure(); Structure initialStructure = new Structure();
CourseNode runRootNode = new STCourseNode(); CourseNode runRootNode = new STCourseNode();
...@@ -286,25 +285,20 @@ public class CourseFactory extends BasicManager { ...@@ -286,25 +285,20 @@ public class CourseFactory extends BasicManager {
*/ */
public static ICourse loadCourse(final Long resourceableId) { public static ICourse loadCourse(final Long resourceableId) {
if (resourceableId == null) throw new AssertException("No resourceable ID found."); if (resourceableId == null) throw new AssertException("No resourceable ID found.");
PersistingCourseImpl course = getCourseFromCache(resourceableId); PersistingCourseImpl course = loadedCourses.get(resourceableId);
if (course == null) { if (course == null) {
// o_clusterOK by:ld - load and put in cache in doInSync block to ensure // o_clusterOK by:ld - load and put in cache in doInSync block to ensure
// that no invalidate cache event was missed // that no invalidate cache event was missed
if (log.isDebug()) log.debug("try to load course with resourceableId=" + resourceableId); PersistingCourseImpl theCourse = new PersistingCourseImpl(resourceableId);
OLATResourceable courseResourceable = OresHelper.createOLATResourceableInstance(PersistingCourseImpl.class, resourceableId); theCourse.load();
course = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(courseResourceable, new SyncerCallback<PersistingCourseImpl>() {
public PersistingCourseImpl execute() { PersistingCourseImpl cachedCourse = loadedCourses.putIfAbsent(resourceableId, theCourse);
PersistingCourseImpl theCourse = getCourseFromCache(resourceableId); if(cachedCourse != null) {
if (theCourse == null) { course = cachedCourse;
theCourse = new PersistingCourseImpl(resourceableId); } else {
theCourse.load(); course = theCourse;
putCourseInCache(resourceableId, theCourse); }
}
return theCourse;
}
});
} }
return course; return course;
} }
...@@ -318,25 +312,6 @@ public class CourseFactory extends BasicManager { ...@@ -318,25 +312,6 @@ public class CourseFactory extends BasicManager {
Long resourceableId = olatResource.getResourceableId(); Long resourceableId = olatResource.getResourceableId();
return loadCourse(resourceableId); return loadCourse(resourceableId);
} }
/**
*
* @param resourceableId
* @return the PersistingCourseImpl instance for the input key.
*/
static PersistingCourseImpl getCourseFromCache(Long resourceableId) { //o_clusterOK by:ld
return loadedCourses.get(resourceableId);
}
/**
* Puts silent.
* @param resourceableId
* @param course
*/
static void putCourseInCache(Long resourceableId, PersistingCourseImpl course) { //o_clusterOK by:ld
loadedCourses.put(resourceableId, course);
log.debug("putCourseInCache ");
}
/** /**
* *
...@@ -584,7 +559,7 @@ public class CourseFactory extends BasicManager { ...@@ -584,7 +559,7 @@ public class CourseFactory extends BasicManager {
CourseConfig cc = CourseConfigManagerImpl.getInstance().loadConfigFor(newCourse); CourseConfig cc = CourseConfigManagerImpl.getInstance().loadConfigFor(newCourse);
//newCourse is not in cache yet, so we cannot call setCourseConfig() //newCourse is not in cache yet, so we cannot call setCourseConfig()
newCourse.setCourseConfig(cc); newCourse.setCourseConfig(cc);
putCourseInCache(newCourse.getResourceableId(), newCourse); loadedCourses.put(newCourse.getResourceableId(), newCourse);
return newCourse; return newCourse;
} catch (AssertException ae) { } catch (AssertException ae) {
// ok failed, cleanup below // ok failed, cleanup below
...@@ -968,13 +943,13 @@ public class CourseFactory extends BasicManager { ...@@ -968,13 +943,13 @@ public class CourseFactory extends BasicManager {
public void execute() { public void execute() {
final PersistingCourseImpl course = getCourseEditSession(resourceableId); final PersistingCourseImpl course = getCourseEditSession(resourceableId);
if(course!=null && course.isReadAndWrite()) { if(course!=null && course.isReadAndWrite()) {
course.initHasAssessableNodes(); course.initHasAssessableNodes();
course.saveRunStructure(); course.saveRunStructure();
course.saveEditorTreeModel(); course.saveEditorTreeModel();
//clear modifyCourseEvents at publish, since the updateCourseInCache is called anyway //clear modifyCourseEvents at publish, since the updateCourseInCache is called anyway
modifyCourseEvents.remove(resourceableId); modifyCourseEvents.remove(resourceableId);
updateCourseInCache(resourceableId, course); updateCourseInCache(resourceableId, course);
} else if(!course.isReadAndWrite()) { } else if(!course.isReadAndWrite()) {
throw new AssertException("Cannot saveCourse because theCourse is readOnly! You have to open an courseEditSession first!"); throw new AssertException("Cannot saveCourse because theCourse is readOnly! You have to open an courseEditSession first!");
} }
...@@ -1083,9 +1058,8 @@ public class CourseFactory extends BasicManager { ...@@ -1083,9 +1058,8 @@ public class CourseFactory extends BasicManager {
public void execute() { public void execute() {
PersistingCourseImpl course = getCourseEditSession(resourceableId); PersistingCourseImpl course = getCourseEditSession(resourceableId);
if(course!=null) { if(course!=null) {
course.setCourseConfig(cc); course.setCourseConfig(cc);
updateCourseInCache(resourceableId, course);
updateCourseInCache(resourceableId, course);
} }
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment