Commit acc02b0e by Don Mitchell Committed by Sarina Canelake

Fix to excess asset query

parent ade82c2d
...@@ -171,7 +171,7 @@ def remove_transcripts_from_store(_step, subs_id): ...@@ -171,7 +171,7 @@ def remove_transcripts_from_store(_step, subs_id):
) )
try: try:
content = contentstore().find(content_location) content = contentstore().find(content_location)
contentstore().delete(content.get_id()) contentstore().delete(content.location)
print('Transcript file was removed from store.') print('Transcript file was removed from store.')
except NotFoundError: except NotFoundError:
print('Transcript file was NOT found and not removed.') print('Transcript file was NOT found and not removed.')
......
...@@ -88,7 +88,7 @@ class TestSaveSubsToStore(ModuleStoreTestCase): ...@@ -88,7 +88,7 @@ class TestSaveSubsToStore(ModuleStoreTestCase):
"""Remove, if subtitles content exists.""" """Remove, if subtitles content exists."""
try: try:
content = contentstore().find(self.content_location) content = contentstore().find(self.content_location)
contentstore().delete(content.get_id()) contentstore().delete(content.location)
except NotFoundError: except NotFoundError:
pass pass
...@@ -171,7 +171,7 @@ class TestDownloadYoutubeSubs(ModuleStoreTestCase): ...@@ -171,7 +171,7 @@ class TestDownloadYoutubeSubs(ModuleStoreTestCase):
content_location = StaticContent.compute_location(self.course.id, filename) content_location = StaticContent.compute_location(self.course.id, filename)
try: try:
content = contentstore().find(content_location) content = contentstore().find(content_location)
contentstore().delete(content.get_id()) contentstore().delete(content.location)
except NotFoundError: except NotFoundError:
pass pass
......
...@@ -59,7 +59,7 @@ class StaticContent(object): ...@@ -59,7 +59,7 @@ class StaticContent(object):
) )
def get_id(self): def get_id(self):
return self.location.to_deprecated_son(tag=XASSET_LOCATION_TAG) return self.location
def get_url_path(self): def get_url_path(self):
return self.location.to_deprecated_string() return self.location.to_deprecated_string()
......
...@@ -12,7 +12,7 @@ from xmodule.exceptions import NotFoundError ...@@ -12,7 +12,7 @@ from xmodule.exceptions import NotFoundError
from fs.osfs import OSFS from fs.osfs import OSFS
import os import os
import json import json
import bson.son from bson.son import SON
from xmodule.modulestore.locations import AssetLocation from xmodule.modulestore.locations import AssetLocation
...@@ -29,7 +29,7 @@ class MongoContentStore(ContentStore): ...@@ -29,7 +29,7 @@ class MongoContentStore(ContentStore):
pymongo.MongoClient( pymongo.MongoClient(
host=host, host=host,
port=port, port=port,
document_class=bson.son.SON, document_class=SON,
**kwargs **kwargs
), ),
db db
...@@ -43,7 +43,7 @@ class MongoContentStore(ContentStore): ...@@ -43,7 +43,7 @@ class MongoContentStore(ContentStore):
self.fs_files = _db[bucket + ".files"] # the underlying collection GridFS uses self.fs_files = _db[bucket + ".files"] # the underlying collection GridFS uses
def save(self, content): def save(self, content):
content_id = content.get_id() content_id = self.asset_db_key(content.location)
# Seems like with the GridFS we can't update existing ID's we have to do a delete/add pair # Seems like with the GridFS we can't update existing ID's we have to do a delete/add pair
self.delete(content_id) self.delete(content_id)
...@@ -71,13 +71,6 @@ class MongoContentStore(ContentStore): ...@@ -71,13 +71,6 @@ class MongoContentStore(ContentStore):
def find(self, location, throw_on_not_found=True, as_stream=False): def find(self, location, throw_on_not_found=True, as_stream=False):
content_id = self.asset_db_key(location) content_id = self.asset_db_key(location)
fs_pointer = self.fs_files.find_one(content_id, fields={'_id': 1})
if fs_pointer is None:
if throw_on_not_found:
raise NotFoundError()
else:
return None
content_id = fs_pointer['_id']
try: try:
if as_stream: if as_stream:
...@@ -104,13 +97,13 @@ class MongoContentStore(ContentStore): ...@@ -104,13 +97,13 @@ class MongoContentStore(ContentStore):
) )
except NoFile: except NoFile:
if throw_on_not_found: if throw_on_not_found:
raise NotFoundError() raise NotFoundError(content_id)
else: else:
return None return None
def get_stream(self, location): def get_stream(self, location):
content_id = self.asset_db_key(location) content_id = self.asset_db_key(location)
fs_pointer = self.fs_files.find_one(content_id, fields={'_id': 1}) fs_pointer = self.fs_files.find_one({'_id': content_id}, fields={'_id': 1})
try: try:
handle = self.fs.get(fs_pointer['_id']) handle = self.fs.get(fs_pointer['_id'])
...@@ -246,10 +239,10 @@ class MongoContentStore(ContentStore): ...@@ -246,10 +239,10 @@ class MongoContentStore(ContentStore):
raise AttributeError("{} is a protected attribute.".format(attr)) raise AttributeError("{} is a protected attribute.".format(attr))
asset_db_key = self.asset_db_key(location) asset_db_key = self.asset_db_key(location)
# FIXME remove fetch and use a form of update which fails if doesn't exist # FIXME remove fetch and use a form of update which fails if doesn't exist
item = self.fs_files.find_one(asset_db_key) item = self.fs_files.find_one({'_id': asset_db_key})
if item is None: if item is None:
raise NotFoundError(asset_db_key) raise NotFoundError(asset_db_key)
self.fs_files.update(asset_db_key, {"$set": attr_dict}) self.fs_files.update({'_id': asset_db_key}, {"$set": attr_dict})
def get_attrs(self, location): def get_attrs(self, location):
""" """
...@@ -262,7 +255,7 @@ class MongoContentStore(ContentStore): ...@@ -262,7 +255,7 @@ class MongoContentStore(ContentStore):
:param location: a c4x asset location :param location: a c4x asset location
""" """
asset_db_key = self.asset_db_key(location) asset_db_key = self.asset_db_key(location)
item = self.fs_files.find_one(asset_db_key) item = self.fs_files.find_one({'_id': asset_db_key})
if item is None: if item is None:
raise NotFoundError(asset_db_key) raise NotFoundError(asset_db_key)
return item return item
......
...@@ -67,8 +67,7 @@ def _clear_assets(location): ...@@ -67,8 +67,7 @@ def _clear_assets(location):
for asset in assets: for asset in assets:
asset_location = AssetLocation._from_deprecated_son(asset["_id"], location.course_key.run) asset_location = AssetLocation._from_deprecated_son(asset["_id"], location.course_key.run)
del_cached_content(asset_location) del_cached_content(asset_location)
mongo_id = asset_location.to_deprecated_son() store.delete(asset_location)
store.delete(mongo_id)
def _get_subs_id(filename): def _get_subs_id(filename):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment