~hadware/magicicada-server/trusty-support

« back to all changes in this revision

Viewing changes to src/backends/db/schemas/fsync_shard/patch_1.py

  • Committer: Facundo Batista
  • Date: 2015-08-05 13:10:02 UTC
  • Revision ID: facundo@taniquetil.com.ar-20150805131002-he7b7k704d8o7js6
First released version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2008-2015 Canonical
 
2
#
 
3
# This program is free software: you can redistribute it and/or modify
 
4
# it under the terms of the GNU Affero General Public License as
 
5
# published by the Free Software Foundation, either version 3 of the
 
6
# License, or (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU Affero General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU Affero General Public License
 
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
15
#
 
16
# For further info, check  http://launchpad.net/filesync-server
 
17
 
 
18
"""Cleanup indexes on Object table.
 
19
 
 
20
Based on feedback from Serius, this patch drops indexes no longer used.
 
21
"""
 
22
 
 
23
SQL = [
 
24
    # this is used when doing magic uploads
 
25
    # CREATE INDEX object_content_hash_fkey ON Object(content_hash)
 
26
    # Since all queries are done using volume_id, owner_id, there is
 
27
    # no need for this index
 
28
    # CREATE INDEX object_owner_id_fkey ON Object(owner_id)
 
29
    """
 
30
    DROP INDEX object_owner_id_fkey;
 
31
    """,
 
32
    # we don't look up nodes only by kind.
 
33
    # CREATE INDEX object_kind ON Object (kind)
 
34
    """
 
35
    DROP INDEX object_kind;
 
36
    """,
 
37
    # This index is not needed
 
38
    # CREATE INDEX object_generation_created_idx ON object(generation_created);
 
39
    """
 
40
    DROP INDEX object_generation_created_idx;
 
41
    """,
 
42
    # This index is not needed
 
43
    # CREATE INDEX object_generation_idx ON object(generation);
 
44
    """
 
45
    DROP INDEX object_generation_idx;
 
46
    """,
 
47
    # Since we are looking up files by owner_id, volume_id, status=Live,
 
48
    # This index never gets used.
 
49
    # CREATE INDEX object_mimtype_idx ON object(mimetype);
 
50
    """
 
51
    DROP INDEX object_mimtype_idx;
 
52
    """,
 
53
    # This index is still important
 
54
    # CREATE UNIQUE INDEX object_parent_name_uk ON object(parent_id, name)
 
55
    #    WHERE (status = 'Live'::lifecycle_status);
 
56
    #
 
57
    # This index is redundant based on the index above
 
58
    #CREATE INDEX object_parent_name_volume
 
59
    #    ON object(parent_id, name, volume_id)
 
60
    #    WHERE ((status = 'Live'::lifecycle_status)
 
61
    #        AND (parent_id IS NOT NULL));
 
62
    """
 
63
    DROP INDEX object_parent_name_volume;
 
64
    """,
 
65
    # This is used to get user's public files for a volume
 
66
    # CREATE INDEX object_publicfile_idx ON object(volume_id, publicfile_id)
 
67
    #    WHERE ((kind = 'File'::object_kind)
 
68
    #           AND (status = 'Live'::lifecycle_status));
 
69
    #
 
70
    # This is no longer used.
 
71
    # CREATE INDEX object_roots ON object(owner_id)
 
72
    #    WHERE ((parent_id IS NULL) AND ((name)::text = ''::text));
 
73
    """
 
74
    DROP INDEX object_roots;
 
75
    """,
 
76
    # This was used when doing mass deletes of old files. we cant do this now.
 
77
    # CREATE INDEX dead_object_last_modified_idx ON object (when_last_modified)
 
78
    #    WHERE (status = 'Dead'::lifecycle_status);
 
79
    """
 
80
    DROP INDEX dead_object_last_modified_idx;
 
81
    """,
 
82
]
 
83
 
 
84
 
 
85
def apply(store):
 
86
    """Apply the patch."""
 
87
    for sql in SQL:
 
88
        store.execute(sql)