Adding our current indexes and removing the index that was in models.py
[mediagoblin.git] / mediagoblin / db / indexes.py
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 """
18 Indexes for the local database.
19
20 Indexes are recorded in the following format:
21
22 INDEXES = {
23 'collection_name': {
24 'identifier': { # key identifier used for possibly deprecating later
25 'index': [index_foo_goes_here]}}
26
27 ... and anything else being parameters to the create_index function
28 (including unique=True, etc)
29
30 Current indexes must be registered in ACTIVE_INDEXES... deprecated
31 indexes should be marked in DEPRECATED_INDEXES.
32
33 Remember, ordering of compound indexes MATTERS. Read below for more.
34
35 REQUIRED READING:
36 - http://kylebanker.com/blog/2010/09/21/the-joy-of-mongodb-indexes/
37
38 - http://www.mongodb.org/display/DOCS/Indexes
39 - http://www.mongodb.org/display/DOCS/Indexing+Advice+and+FAQ
40
41
42 """
43
44 from pymongo import ASCENDING, DESCENDING
45
46
47 ################
48 # Active indexes
49 ################
50 ACTIVE_INDEXES = {}
51
52 # MediaEntry indexes
53 # ------------------
54
55 MEDIAENTRY_INDEXES = {
56 'uploader_slug_unique': {
57 # Matching an object to an uploader + slug.
58 # MediaEntries are unique on these two combined, eg:
59 # /u/${myuser}/m/${myslugname}/
60 'index': [('uploader', ASCENDING),
61 ('slug', ASCENDING)],
62 'unique': True},
63
64 'created': {
65 # A global index for all media entries created, in descending
66 # order. This is used for the site's frontpage.
67 'index': [('created', DESCENDING)]},
68
69 'uploader_created': {
70 # Indexing on uploaders and when media entries are created.
71 # Used for showing a user gallery, etc.
72 'index': [('uploader', ASCENDING),
73 ('created', DESCENDING)]}}
74
75
76 ACTIVE_INDEXES['media_entries'] = MEDIAENTRY_INDEXES
77
78
79 # User indexes
80 # ------------
81
82 USER_INDEXES = {
83 'username_unique': {
84 # Index usernames, and make sure they're unique.
85 # ... I guess we might need to adjust this once we're federated :)
86 'index': 'username',
87 'unique': True},
88 'created': {
89 # All most recently created users
90 'index': 'created'}}
91
92
93 ACTIVE_INDEXES['users'] = USER_INDEXES
94
95
96 ####################
97 # Deprecated indexes
98 ####################
99
100 # @@: Do we really need to keep the index form if we're removing by
101 # key name? I guess it's helpful to keep the record...
102
103
104 DEPRECATED_INDEXES = {}