Skip to content

Commit 0686a73

Browse files
committed
models: Split 'CoverLetter' from 'Submission'
We want to get rid of the split between 'Patch' and 'Submission' because of the cost of using JOINs basically everywhere we use 'Patch'. Before we do that, we need to move the other users of 'Submission' to other models and other models that rely on these users sharing the common 'Submission' base. For the former, there is only one user, 'CoverLetter', while for the latter there is only the 'Comment' model. As a result, we must do the following: - Create a new 'Cover' model - Create a new 'CoverComment' model - Move everything from 'CoverLetter' to 'Cover' and all entries associated with a 'CoverLetter' from 'Comment' to 'CoverComment' - Delete the 'CoverLetter' model - Rename the 'Comment' model to 'PatchComment' This means our model "hierarchy" goes from: Submission Patch CoverLetter Comment To: Submission Patch PatchComment Cover CoverComment A future change will flatten the 'Submission' and 'Patch' model. Note that this actually highlighted a bug in Django, which has since been reported upstream [1]. As noted there, the issue stems from MySQL's refusal to remove an index from a foreign key when DB constraints are used and the workaround is to remove the foreign key constraint before altering the indexes and then re-add the constraint after. [1] https://code.djangoproject.com/ticket/31335 Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 13ff6b2 commit 0686a73

22 files changed

Lines changed: 600 additions & 148 deletions

patchwork/admin.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
from patchwork.models import Bundle
1212
from patchwork.models import Check
13-
from patchwork.models import Comment
14-
from patchwork.models import CoverLetter
13+
from patchwork.models import Cover
14+
from patchwork.models import CoverComment
1515
from patchwork.models import DelegationRule
1616
from patchwork.models import Patch
17+
from patchwork.models import PatchComment
1718
from patchwork.models import PatchRelation
1819
from patchwork.models import Person
1920
from patchwork.models import Project
@@ -75,14 +76,14 @@ class StateAdmin(admin.ModelAdmin):
7576
admin.site.register(State, StateAdmin)
7677

7778

78-
class CoverLetterAdmin(admin.ModelAdmin):
79+
class CoverAdmin(admin.ModelAdmin):
7980
list_display = ('name', 'submitter', 'project', 'date')
8081
list_filter = ('project', )
8182
search_fields = ('name', 'submitter__name', 'submitter__email')
8283
date_hierarchy = 'date'
8384

8485

85-
admin.site.register(CoverLetter, CoverLetterAdmin)
86+
admin.site.register(Cover, CoverAdmin)
8687

8788

8889
class PatchAdmin(admin.ModelAdmin):
@@ -104,13 +105,22 @@ def is_pull_request(self, patch):
104105
admin.site.register(Patch, PatchAdmin)
105106

106107

107-
class CommentAdmin(admin.ModelAdmin):
108-
list_display = ('submission', 'submitter', 'date')
109-
search_fields = ('submission__name', 'submitter__name', 'submitter__email')
108+
class CoverCommentAdmin(admin.ModelAdmin):
109+
list_display = ('cover', 'submitter', 'date')
110+
search_fields = ('cover__name', 'submitter__name', 'submitter__email')
110111
date_hierarchy = 'date'
111112

112113

113-
admin.site.register(Comment, CommentAdmin)
114+
admin.site.register(CoverComment, CoverCommentAdmin)
115+
116+
117+
class PatchCommentAdmin(admin.ModelAdmin):
118+
list_display = ('patch', 'submitter', 'date')
119+
search_fields = ('patch__name', 'submitter__name', 'submitter__email')
120+
date_hierarchy = 'date'
121+
122+
123+
admin.site.register(PatchComment, PatchCommentAdmin)
114124

115125

116126
class PatchInline(admin.StackedInline):

patchwork/api/comment.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
from patchwork.api.base import BaseHyperlinkedModelSerializer
1313
from patchwork.api.base import PatchworkPermission
1414
from patchwork.api.embedded import PersonSerializer
15-
from patchwork.models import Comment
15+
from patchwork.models import Cover
16+
from patchwork.models import CoverComment
1617
from patchwork.models import Submission
18+
from patchwork.models import PatchComment
1719

1820

19-
class CommentListSerializer(BaseHyperlinkedModelSerializer):
21+
class BaseCommentListSerializer(BaseHyperlinkedModelSerializer):
2022

2123
web_url = SerializerMethodField()
2224
subject = SerializerMethodField()
@@ -46,7 +48,6 @@ def get_headers(self, comment):
4648
return headers
4749

4850
class Meta:
49-
model = Comment
5051
fields = ('id', 'web_url', 'msgid', 'list_archive_url', 'date',
5152
'subject', 'submitter', 'content', 'headers')
5253
read_only_fields = fields
@@ -56,11 +57,48 @@ class Meta:
5657
}
5758

5859

59-
class CommentList(ListAPIView):
60+
class CoverCommentListSerializer(BaseCommentListSerializer):
61+
62+
class Meta:
63+
model = CoverComment
64+
fields = BaseCommentListSerializer.Meta.fields
65+
read_only_fields = fields
66+
versioned_fields = BaseCommentListSerializer.Meta.versioned_fields
67+
68+
69+
class PatchCommentListSerializer(BaseCommentListSerializer):
70+
71+
class Meta:
72+
model = PatchComment
73+
fields = BaseCommentListSerializer.Meta.fields
74+
read_only_fields = fields
75+
versioned_fields = BaseCommentListSerializer.Meta.versioned_fields
76+
77+
78+
class CoverCommentList(ListAPIView):
79+
"""List cover comments"""
80+
81+
permission_classes = (PatchworkPermission,)
82+
serializer_class = CoverCommentListSerializer
83+
search_fields = ('subject',)
84+
ordering_fields = ('id', 'subject', 'date', 'submitter')
85+
ordering = 'id'
86+
lookup_url_kwarg = 'pk'
87+
88+
def get_queryset(self):
89+
if not Cover.objects.filter(pk=self.kwargs['pk']).exists():
90+
raise Http404
91+
92+
return CoverComment.objects.filter(
93+
cover=self.kwargs['pk']
94+
).select_related('submitter')
95+
96+
97+
class PatchCommentList(ListAPIView):
6098
"""List comments"""
6199

62100
permission_classes = (PatchworkPermission,)
63-
serializer_class = CommentListSerializer
101+
serializer_class = PatchCommentListSerializer
64102
search_fields = ('subject',)
65103
ordering_fields = ('id', 'subject', 'date', 'submitter')
66104
ordering = 'id'
@@ -70,6 +108,6 @@ def get_queryset(self):
70108
if not Submission.objects.filter(pk=self.kwargs['pk']).exists():
71109
raise Http404
72110

73-
return Comment.objects.filter(
74-
submission=self.kwargs['pk']
111+
return PatchComment.objects.filter(
112+
patch=self.kwargs['pk']
75113
).select_related('submitter')

patchwork/api/cover.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from patchwork.api.embedded import PersonSerializer
1616
from patchwork.api.embedded import ProjectSerializer
1717
from patchwork.api.embedded import SeriesSerializer
18-
from patchwork.models import CoverLetter
18+
from patchwork.models import Cover
1919

2020

2121
class CoverListSerializer(BaseHyperlinkedModelSerializer):
@@ -49,7 +49,7 @@ def to_representation(self, instance):
4949
return data
5050

5151
class Meta:
52-
model = CoverLetter
52+
model = Cover
5353
fields = ('id', 'url', 'web_url', 'project', 'msgid',
5454
'list_archive_url', 'date', 'name', 'submitter', 'mbox',
5555
'series', 'comments')
@@ -82,7 +82,7 @@ def get_headers(self, instance):
8282
return headers
8383

8484
class Meta:
85-
model = CoverLetter
85+
model = Cover
8686
fields = CoverListSerializer.Meta.fields + (
8787
'headers', 'content')
8888
read_only_fields = fields
@@ -100,7 +100,7 @@ class CoverList(ListAPIView):
100100
ordering = 'id'
101101

102102
def get_queryset(self):
103-
return CoverLetter.objects.all()\
103+
return Cover.objects.all()\
104104
.prefetch_related('series__project')\
105105
.select_related('project', 'submitter', 'series')\
106106
.defer('content', 'headers')
@@ -112,5 +112,5 @@ class CoverDetail(RetrieveAPIView):
112112
serializer_class = CoverDetailSerializer
113113

114114
def get_queryset(self):
115-
return CoverLetter.objects.all()\
115+
return Cover.objects.all()\
116116
.select_related('project', 'submitter', 'series')

patchwork/api/embedded.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class CoverSerializer(SerializedRelatedField):
108108
class _Serializer(MboxMixin, WebURLMixin, BaseHyperlinkedModelSerializer):
109109

110110
class Meta:
111-
model = models.CoverLetter
111+
model = models.Cover
112112
fields = ('id', 'url', 'web_url', 'msgid', 'list_archive_url',
113113
'date', 'name', 'mbox')
114114
read_only_fields = fields

patchwork/api/filters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from patchwork.api import utils
1919
from patchwork.models import Bundle
2020
from patchwork.models import Check
21-
from patchwork.models import CoverLetter
21+
from patchwork.models import Cover
2222
from patchwork.models import Event
2323
from patchwork.models import Patch
2424
from patchwork.models import Person
@@ -199,7 +199,7 @@ class CoverFilterSet(TimestampMixin, BaseFilterSet):
199199
msgid = CharFilter(method=msgid_filter)
200200

201201
class Meta:
202-
model = CoverLetter
202+
model = Cover
203203
fields = ('project', 'series', 'submitter')
204204

205205

@@ -253,7 +253,7 @@ class EventFilterSet(TimestampMixin, BaseFilterSet):
253253
patch = BaseFilter(queryset=Patch.objects.all(),
254254
widget=MultipleHiddenInput,
255255
distinct=False)
256-
cover = BaseFilter(queryset=CoverLetter.objects.all(),
256+
cover = BaseFilter(queryset=Cover.objects.all(),
257257
widget=MultipleHiddenInput,
258258
distinct=False)
259259

patchwork/management/commands/parsearchive.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def add_arguments(self, parser):
3232
def handle(self, *args, **options):
3333
results = {
3434
models.Patch: 0,
35-
models.CoverLetter: 0,
36-
models.Comment: 0,
35+
models.Cover: 0,
36+
models.PatchComment: 0,
37+
models.CoverComment: 0,
3738
}
3839
duplicates = 0
3940
dropped = 0
@@ -118,9 +119,11 @@ def handle(self, *args, **options):
118119
' %(errors)4d errors\n'
119120
'Total: %(new)s new entries' % {
120121
'total': count,
121-
'covers': results[models.CoverLetter],
122+
'covers': results[models.Cover],
122123
'patches': results[models.Patch],
123-
'comments': results[models.Comment],
124+
'comments': (
125+
results[models.CoverComment] + results[models.PatchComment]
126+
),
124127
'duplicates': duplicates,
125128
'dropped': dropped,
126129
'errors': errors,

0 commit comments

Comments
 (0)