adapt-authoring-courseassets 1.4.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -68,20 +68,32 @@ class CourseAssetsModule extends AbstractApiModule {
68
68
  if (!contentId || !courseId) {
69
69
  return
70
70
  }
71
- // delete any existing course assets for content
72
- await this.deleteMany({ courseId, contentId })
73
-
74
71
  const data = isModify ? arg2 : arg1
75
72
  const schema = await this.content.getSchema(this.content.schemaName, data)
76
73
  const ids = extractAssetIds(schema.built.properties, data)
77
74
 
75
+ if (isModify) {
76
+ const existing = await this.find({ courseId, contentId })
77
+ const existingIds = existing.map(r => r.assetId.toString()).sort()
78
+ if (ids.length === existingIds.length && ids.slice().sort().every((id, i) => id === existingIds[i])) {
79
+ return
80
+ }
81
+ }
82
+ // delete any existing course assets for content
83
+ await this.deleteMany({ courseId, contentId })
84
+
78
85
  if (!ids.length) {
79
86
  return
80
87
  }
81
- await Promise.all(ids.map(async _id => {
82
- const asset = await this.assets.findOne({ _id })
83
- await this.insert({ courseId, contentId, assetId: _id })
84
- }))
88
+ const found = await this.assets.find({ _id: { $in: ids } })
89
+ const foundIds = new Set(found.map(a => a._id.toString()))
90
+ const validIds = ids.filter(id => foundIds.has(id))
91
+
92
+ if (validIds.length) {
93
+ const mongodb = await this.app.waitForModule('mongodb')
94
+ const docs = validIds.map(assetId => ({ courseId, contentId, assetId }))
95
+ await mongodb.getCollection(this.collectionName).insertMany(docs)
96
+ }
85
97
  this.log('debug', 'UPDATE', courseId, contentId)
86
98
  }
87
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-courseassets",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "Module for managing course asset usage",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-courseassets",
6
6
  "license": "GPL-3.0",