##// END OF EJS Templates
Store UUID for posts and get thread diff by UUIDs instead of update time or...
neko259 -
r1118:01343b9e default
parent child Browse files
Show More
@@ -0,0 +1,19 b''
1 from django.core.management import BaseCommand
2 from django.db import transaction
3 from django.db.models import Count
4
5 from boards.models import Tag
6
7
8 __author__ = 'neko259'
9
10
11 class Command(BaseCommand):
12 help = 'Removed tags that have no threads'
13
14 @transaction.atomic
15 def handle(self, *args, **options):
16 empty = Tag.objects.annotate(num_threads=Count('thread'))\
17 .filter(num_threads=0).order_by('-required', 'name')
18 print('Removing {} empty tags'.format(empty.count()))
19 empty.delete()
@@ -0,0 +1,29 b''
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import uuid
5
6 from django.db import models, migrations
7
8
9 class Migration(migrations.Migration):
10
11 def assign_uids(apps, schema_editor):
12 Post = apps.get_model('boards', 'Post')
13 for post in Post.objects.all():
14 post.uid = str(uuid.uuid4())
15 post.save(update_fields=['uid'])
16
17 dependencies = [
18 ('boards', '0014_auto_20150418_1749'),
19 ]
20
21 operations = [
22 migrations.AddField(
23 model_name='post',
24 name='uid',
25 field=models.TextField(default=''),
26 preserve_default=False,
27 ),
28 migrations.RunPython(assign_uids),
29 ]
@@ -10,7 +10,7 b' class PostAdmin(admin.ModelAdmin):'
10 10 list_filter = ('pub_time',)
11 11 search_fields = ('id', 'title', 'text')
12 12 exclude = ('referenced_posts', 'refmap')
13 readonly_fields = ('poster_ip', 'threads', 'thread', 'images')
13 readonly_fields = ('poster_ip', 'threads', 'thread', 'images', 'uid')
14 14
15 15 def ban_poster(self, request, queryset):
16 16 bans = 0
@@ -2,6 +2,7 b' from datetime import datetime, timedelta'
2 2 from datetime import time as dtime
3 3 import logging
4 4 import re
5 import uuid
5 6
6 7 from django.core.exceptions import ObjectDoesNotExist
7 8 from django.core.urlresolvers import reverse
@@ -175,7 +176,9 b' class Post(models.Model, Viewable):'
175 176 refmap = models.TextField(null=True, blank=True)
176 177 threads = models.ManyToManyField('Thread', db_index=True)
177 178 thread = models.ForeignKey('Thread', db_index=True, related_name='pt+')
179
178 180 url = models.TextField()
181 uid = models.TextField()
179 182
180 183 def __str__(self):
181 184 return 'P#{}/{}'.format(self.id, self.title)
@@ -358,6 +361,10 b' class Post(models.Model, Viewable):'
358 361 update_fields=None):
359 362 self._text_rendered = Parser().parse(self.get_raw_text())
360 363
364 self.uid = str(uuid.uuid4())
365 if update_fields is not None and 'uid' not in update_fields:
366 update_fields += ['uid']
367
361 368 if self.id:
362 369 for thread in self.get_threads().all():
363 370 if thread.can_bump():
@@ -86,26 +86,21 b' function getThreadDiff() {'
86 86 var lastUpdateTime = $('.metapanel').attr('data-last-update');
87 87 var lastPostId = $('.post').last().attr('id');
88 88
89 var diffUrl = '/api/diff_thread?thread=' + threadId + '&last_update=' + encodeURIComponent(lastUpdateTime)
90 + '&last_post=' + lastPostId;
91
92 $.getJSON(diffUrl)
93 .success(function(data) {
94 var addedPosts = data.added;
89 var uids = '';
90 var posts = $('.post');
91 for (var i = 0; i < posts.length; i++) {
92 uids += posts[i].getAttribute('data-uid') + ' ';
93 }
95 94
96 for (var i = 0; i < addedPosts.length; i++) {
97 var postText = addedPosts[i];
98 var post = $(postText);
99
100 updatePost(post);
101 }
95 var data = {
96 uids: uids
97 }
102 98
103 var addedPostsCount = addedPosts.length;
104 if (addedPostsCount > 0) {
105 updateBumplimitProgress(addedPostsCount);
106 showNewPostsTitle(addedPostsCount);
107 }
99 var diffUrl = '/api/diff_thread?thread=' + threadId;
108 100
101 $.post(diffUrl,
102 data,
103 function(data) {
109 104 var updatedPosts = data.updated;
110 105
111 106 for (var i = 0; i < updatedPosts.length; i++) {
@@ -115,14 +110,16 b' function getThreadDiff() {'
115 110 updatePost(post);
116 111 }
117 112
118 var hasMetaUpdates = addedPostsCount > 0 || updatedPosts.length > 0;
113 var hasMetaUpdates = updatedPosts.length > 0;
119 114 if (hasMetaUpdates) {
120 115 updateMetadataPanel();
121 116 }
122 117
123 118 // TODO Process removed posts if any
124 119 $('.metapanel').attr('data-last-update', data.last_update);
125 })
120 },
121 'json'
122 )
126 123 }
127 124
128 125 /**
@@ -150,6 +147,9 b' function updatePost(postHtml) {'
150 147 if (bottom) {
151 148 scrollToBottom();
152 149 }
150
151 updateBumplimitProgress(1);
152 showNewPostsTitle(1);
153 153 }
154 154
155 155 processNewPost(post);
@@ -3,7 +3,7 b''
3 3
4 4 {% get_current_language as LANGUAGE_CODE %}
5 5
6 <div class="{{ css_class }}" id="{{ post.id }}">
6 <div class="{{ css_class }}" id="{{ post.id }}" data-uid="{{ post.uid }}">
7 7 <div class="post-info">
8 8 <a class="post_id" href="{{ post.get_url }}">({{ post.get_absolute_id }})</a>
9 9 <span class="title">{{ post.title }}</span>
@@ -40,28 +40,20 b' def api_get_threaddiff(request):'
40 40 """
41 41
42 42 thread_id = request.GET.get('thread')
43 last_update_time = request.GET.get('last_update')
44 last_post = request.GET.get('last_post')
43 uids_str = request.POST.get('uids').strip()
44 uids = uids_str.split(' ')
45 45
46 46 thread = get_object_or_404(Post, id=thread_id).get_thread()
47 47
48 48 json_data = {
49 PARAMETER_ADDED: [],
50 49 PARAMETER_UPDATED: [],
51 50 'last_update': None,
52 51 }
53 added_posts = Post.objects.filter(threads__in=[thread],
54 id__gt=int(last_post)) \
55 .order_by('pub_time')
56 updated_posts = Post.objects.filter(threads__in=[thread],
57 pub_time__lte=last_update_time,
58 last_edit_time__gt=last_update_time)
52 posts = Post.objects.filter(threads__in=[thread]).exclude(uid__in=uids)
59 53
60 54 diff_type = request.GET.get(PARAMETER_DIFF_TYPE, DIFF_TYPE_HTML)
61 55
62 for post in added_posts:
63 json_data[PARAMETER_ADDED].append(get_post_data(post.id, diff_type, request))
64 for post in updated_posts:
56 for post in posts:
65 57 json_data[PARAMETER_UPDATED].append(get_post_data(post.id, diff_type, request))
66 58 json_data[PARAMETER_LAST_UPDATE] = str(thread.last_edit_time)
67 59
General Comments 0
You need to be logged in to leave comments. Login now