Skip to content

Commit

Permalink
Bug 714318 - Use a single collection namespace for all users; r=telliott
Browse files Browse the repository at this point in the history
  • Loading branch information
rfk committed Mar 2, 2012
1 parent e3ca981 commit 4858e02
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 379 deletions.
2 changes: 1 addition & 1 deletion syncstorage/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_storage(self, request):
# XXX returns a 400 if the root is called
raise HTTPBadRequest()

def get_collections(self, request, **metrics):
def get_collection_timestamps(self, request):
"""Returns a hash of collections associated with the account,
Along with the last modified timestamp for each collection
"""
Expand Down
74 changes: 0 additions & 74 deletions syncstorage/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,80 +30,6 @@ def get_name(self):
#
# Collections APIs
#
@abc.abstractmethod
def delete_collection(self, user_id, collection_name):
"""Deletes a collection.
Args:
- user_id: integer identifying the user in the storage.
- collection_name: name of the collection
Returns:
None
"""

@abc.abstractmethod
def collection_exists(self, user_id, collection_name):
"""Returns True if the collection exists.
Args:
- user_id: integer identifying the user in the storage.
- collection_name: name of the collection
Returns:
True or False
"""

@abc.abstractmethod
def set_collection(self, user_id, collection_name, **values):
"""Creates a new collection.
Args:
- user_id: integer identifying the user in the storage.
- collection_name: name of the collection.
- values: mapping containing the values.
Returns:
integer identifying the collection in the storage.
"""

@abc.abstractmethod
def get_collection(self, user_id, collection_name, fields=None):
"""Return information about a collection.
Args:
- user_id: integer identifying the user in the storage.
- collection_name: name of the collection.
- fields: if provided, its a list of fields to return,
all fields are returns by default.
Returns:
A dict containing the information for the collection
"""

@abc.abstractmethod
def get_collections(self, user_id, fields=None):
"""Returns the collections information.
Args:
- user_id: integer identifying the user in the storage.
- fields: if provided, its a list of fields to return,
all fields are returns by default.
Returns:
A list of dict containing the information for the collection
"""

@abc.abstractmethod
def get_collection_names(self, user_id):
"""Returns the collection names for a user.
Args:
user_id: integer identifying the user in the storage.
Returns:
A list of dict containing the name and id for each collection.
"""

@abc.abstractmethod
def get_collection_timestamps(self, user_id):
Expand Down
4 changes: 3 additions & 1 deletion syncstorage/storage/memcachedsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ def set_items(self, user_id, collection_name, items, storage_time=None):
for item in items:
self._update_item(item, storage_time)

self._update_cache(user_id, collection_name, items, storage_time)
if items:
self._update_cache(user_id, collection_name, items, storage_time)

if collection_name == 'tabs':
# return now : we don't store tabs in sql
return len(items)
Expand Down
51 changes: 14 additions & 37 deletions syncstorage/storage/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,30 @@
query while taking BSO table sharding into account.
"""

from syncstorage.storage.sqlmappers import collections, bso, get_bso_table
from sqlalchemy.sql import select, bindparam, delete, and_, text

_USER_N_COLL = and_(collections.c.userid == bindparam('user_id'),
collections.c.name == bindparam('collection_name'))
from syncstorage.storage.sqlmappers import bso, get_bso_table
from sqlalchemy.sql import bindparam, and_, text

queries = {
'DELETE_SOME_USER_BSO': 'DELETE FROM %(bso)s WHERE userid=:user_id AND '
'collection=:collection_id AND id=:item_id',

'DELETE_USER_COLLECTIONS': 'DELETE FROM collections WHERE '
'userid=:user_id',

'DELETE_USER_COLLECTION': delete(collections).where(_USER_N_COLL),

'DELETE_USER_BSOS': 'DELETE FROM %(bso)s WHERE userid=:user_id',

'COLLECTION_EXISTS': select([collections.c.collectionid], _USER_N_COLL),

'COLLECTION_NEXTID': 'SELECT MAX(collectionid) FROM collections '
'WHERE userid=:user_id',
'COLLECTIONS_MAX_STAMPS': 'SELECT collection, MAX(modified) FROM %(bso)s '
'WHERE userid=:user_id GROUP BY userid, '
'collection',

'COLLECTION_MODIFIED': 'SELECT bso_a.modified FROM %(bso)s AS bso_a, '
'%(bso)s WHERE bso_a.userid=%(bso)s.userid '
'AND bso_a.collection=%(bso)s.collection '
'ORDER BY bso_a.userid DESC, '
'bso_a.collection DESC, bso_a.modified DESC '
'LIMIT 1',
'COLLECTIONS_COUNTS': 'SELECT collection, COUNT(collection) FROM %(bso)s '
'WHERE userid=:user_id AND ttl>:ttl '
'GROUP BY collection',

'COLLECTION_STAMPS': 'SELECT collection, MAX(modified) FROM %(bso)s '
'WHERE userid=:user_id GROUP BY userid, '
'collection',

'COLLECTION_COUNTS': 'SELECT collection, COUNT(collection) FROM %(bso)s '
'WHERE userid=:user_id AND ttl>:ttl '
'GROUP BY collection',
'COLLECTIONS_STORAGE_SIZE': 'SELECT collection, SUM(payload_size) '
'FROM %(bso)s WHERE userid=:user_id AND '
'ttl>:ttl GROUP BY collection',

'COLLECTION_MAX_STAMPS': 'SELECT MAX(modified) FROM %(bso)s WHERE '
'collection=:collection_id AND '
'userid=:user_id',
'COLLECTION_MAX_STAMP': 'SELECT MAX(modified) FROM %(bso)s WHERE '
'collection=:collection_id AND '
'userid=:user_id',

'ITEM_EXISTS': 'SELECT modified FROM %(bso)s WHERE '
'collection=:collection_id AND userid=:user_id '
Expand All @@ -59,13 +43,6 @@

'USER_STORAGE_SIZE': 'SELECT SUM(payload_size) FROM %(bso)s WHERE '
'userid=:user_id AND ttl>:ttl',

'COLLECTIONS_STORAGE_SIZE': 'SELECT collection, SUM(payload_size) '
'FROM %(bso)s WHERE userid=:user_id AND '
'ttl>:ttl GROUP BY collection',

'USER_COLLECTION_NAMES': 'SELECT collectionid, name FROM collections '
'WHERE userid=:user_id',
}


Expand Down
Loading

0 comments on commit 4858e02

Please sign in to comment.