changes tags to a list of dicts in the db, adding tag slugs
[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
1f774999
CAW
20To add new indexes
21------------------
22
3cd6ea5b
CAW
23Indexes are recorded in the following format:
24
1f774999 25ACTIVE_INDEXES = {
ca5d2c51
CAW
26 'collection_name': {
27 'identifier': { # key identifier used for possibly deprecating later
28 'index': [index_foo_goes_here]}}
3cd6ea5b
CAW
29
30... and anything else being parameters to the create_index function
31(including unique=True, etc)
32
33Current indexes must be registered in ACTIVE_INDEXES... deprecated
34indexes should be marked in DEPRECATED_INDEXES.
35
36Remember, ordering of compound indexes MATTERS. Read below for more.
37
38REQUIRED READING:
39 - http://kylebanker.com/blog/2010/09/21/the-joy-of-mongodb-indexes/
ca5d2c51 40
3cd6ea5b
CAW
41 - http://www.mongodb.org/display/DOCS/Indexes
42 - http://www.mongodb.org/display/DOCS/Indexing+Advice+and+FAQ
b1db6f20
CAW
43
44
1f774999
CAW
45To remove deprecated indexes
46----------------------------
47
48Removing deprecated indexes is easier, just do:
49
50INACTIVE_INDEXES = {
51 'collection_name': [
52 'deprecated_index_identifier1', 'deprecated_index_identifier2']}
53
54... etc.
55
56If an index has been deprecated that identifier should NEVER BE USED
57AGAIN. Eg, if you previously had 'awesomepants_unique', you shouldn't
58use 'awesomepants_unique' again, you should create a totally new name
59or at worst use 'awesomepants_unique2'.
3cd6ea5b
CAW
60"""
61
62from pymongo import ASCENDING, DESCENDING
63
64
65################
66# Active indexes
67################
68ACTIVE_INDEXES = {}
69
70# MediaEntry indexes
71# ------------------
72
73MEDIAENTRY_INDEXES = {
b1db6f20 74 'uploader_slug_unique': {
3cd6ea5b
CAW
75 # Matching an object to an uploader + slug.
76 # MediaEntries are unique on these two combined, eg:
77 # /u/${myuser}/m/${myslugname}/
3cd6ea5b
CAW
78 'index': [('uploader', ASCENDING),
79 ('slug', ASCENDING)],
80 'unique': True},
81
b1db6f20 82 'created': {
3cd6ea5b
CAW
83 # A global index for all media entries created, in descending
84 # order. This is used for the site's frontpage.
3cd6ea5b
CAW
85 'index': [('created', DESCENDING)]},
86
b1db6f20 87 'uploader_created': {
3cd6ea5b
CAW
88 # Indexing on uploaders and when media entries are created.
89 # Used for showing a user gallery, etc.
3cd6ea5b 90 'index': [('uploader', ASCENDING),
272469da
CFD
91 ('created', DESCENDING)]},
92
cea8f2b6
CFD
93 'state_uploader_tags_created': {
94 # Indexing on processed?, media uploader, associated tags, and timestamp
272469da 95 # Used for showing media items matching a tag search, most recent first.
cea8f2b6
CFD
96 'index': [('state', ASCENDING),
97 ('uploader', ASCENDING),
272469da 98 ('tags', DESCENDING),
1580c7c5
CFD
99 ('created', DESCENDING)]},
100
cea8f2b6
CFD
101 'state_tags_created': {
102 # Indexing on processed?, media tags, and timestamp (across all users)
1580c7c5 103 # This is used for a front page tag search.
cea8f2b6
CFD
104 'index': [('state', ASCENDING),
105 ('tags', DESCENDING),
3cd6ea5b
CAW
106 ('created', DESCENDING)]}}
107
108
ca5d2c51 109ACTIVE_INDEXES['media_entries'] = MEDIAENTRY_INDEXES
3cd6ea5b
CAW
110
111
112# User indexes
113# ------------
114
115USER_INDEXES = {
b1db6f20 116 'username_unique': {
3cd6ea5b
CAW
117 # Index usernames, and make sure they're unique.
118 # ... I guess we might need to adjust this once we're federated :)
ca5d2c51
CAW
119 'index': 'username',
120 'unique': True},
b1db6f20 121 'created': {
3cd6ea5b 122 # All most recently created users
3cd6ea5b 123 'index': 'created'}}
b1db6f20 124
3cd6ea5b 125
ca5d2c51 126ACTIVE_INDEXES['users'] = USER_INDEXES
3cd6ea5b
CAW
127
128
a98104eb
CAW
129# MediaComment indexes
130
131MEDIA_COMMENT_INDEXES = {
132 'mediaentry_created': {
133 'index': [('media_entry', ASCENDING),
134 ('created', DESCENDING)]}}
135
136ACTIVE_INDEXES['media_comments'] = MEDIA_COMMENT_INDEXES
137
138
3cd6ea5b
CAW
139####################
140# Deprecated indexes
141####################
142
ca5d2c51 143DEPRECATED_INDEXES = {}