Tools to add / remove indexes from collections
[mediagoblin.git] / mediagoblin / db / indexes.py
CommitLineData
3cd6ea5b
CAW
1# GNU MediaGoblin -- federated, autonomous media hosting
2# Copyright (C) 2011 Free Software Foundation, Inc
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17"""
18Indexes for the local database.
19
20Indexes are recorded in the following format:
21
22INDEXES = {
ca5d2c51
CAW
23 'collection_name': {
24 'identifier': { # key identifier used for possibly deprecating later
25 'index': [index_foo_goes_here]}}
3cd6ea5b
CAW
26
27... and anything else being parameters to the create_index function
28(including unique=True, etc)
29
30Current indexes must be registered in ACTIVE_INDEXES... deprecated
31indexes should be marked in DEPRECATED_INDEXES.
32
33Remember, ordering of compound indexes MATTERS. Read below for more.
34
35REQUIRED READING:
36 - http://kylebanker.com/blog/2010/09/21/the-joy-of-mongodb-indexes/
ca5d2c51 37
3cd6ea5b
CAW
38 - http://www.mongodb.org/display/DOCS/Indexes
39 - http://www.mongodb.org/display/DOCS/Indexing+Advice+and+FAQ
40"""
41
42from pymongo import ASCENDING, DESCENDING
43
44
45################
46# Active indexes
47################
48ACTIVE_INDEXES = {}
49
50# MediaEntry indexes
51# ------------------
52
53MEDIAENTRY_INDEXES = {
54 'mediaentry_uploader_slug_unique': {
55 # Matching an object to an uploader + slug.
56 # MediaEntries are unique on these two combined, eg:
57 # /u/${myuser}/m/${myslugname}/
3cd6ea5b
CAW
58 'index': [('uploader', ASCENDING),
59 ('slug', ASCENDING)],
60 'unique': True},
61
62 'mediaentry_created': {
63 # A global index for all media entries created, in descending
64 # order. This is used for the site's frontpage.
3cd6ea5b
CAW
65 'index': [('created', DESCENDING)]},
66
67 'mediaentry_uploader_created': {
68 # Indexing on uploaders and when media entries are created.
69 # Used for showing a user gallery, etc.
3cd6ea5b
CAW
70 'index': [('uploader', ASCENDING),
71 ('created', DESCENDING)]}}
72
73
ca5d2c51 74ACTIVE_INDEXES['media_entries'] = MEDIAENTRY_INDEXES
3cd6ea5b
CAW
75
76
77# User indexes
78# ------------
79
80USER_INDEXES = {
81 'user_username_unique': {
82 # Index usernames, and make sure they're unique.
83 # ... I guess we might need to adjust this once we're federated :)
ca5d2c51
CAW
84 'index': 'username',
85 'unique': True},
3cd6ea5b
CAW
86 'user_created': {
87 # All most recently created users
3cd6ea5b
CAW
88 'index': 'created'}}
89
90
ca5d2c51 91ACTIVE_INDEXES['users'] = USER_INDEXES
3cd6ea5b
CAW
92
93
94####################
95# Deprecated indexes
96####################
97
ca5d2c51 98DEPRECATED_INDEXES = {}