diff --git a/boards/management/commands/invalidate_sync_cache.py b/boards/management/commands/invalidate_sync_cache.py new file mode 100644 --- /dev/null +++ b/boards/management/commands/invalidate_sync_cache.py @@ -0,0 +1,20 @@ +from django.core.management import BaseCommand +from django.db import transaction + +from boards.models import GlobalId + +__author__ = 'neko259' + + +class Command(BaseCommand): + help = 'Removes local global ID cache' + + @transaction.atomic + def handle(self, *args, **options): + count = 0 + for global_id in GlobalId.objects.all(): + if global_id.is_local() and global_id.content is not None: + global_id.content = None + global_id.save() + count += 1 + print('Invalidated {} caches.'.format(count)) diff --git a/boards/models/__init__.py b/boards/models/__init__.py --- a/boards/models/__init__.py +++ b/boards/models/__init__.py @@ -3,8 +3,8 @@ STATUS_BUMPLIMIT = 'bumplimit' STATUS_ARCHIVE = 'archived' +from boards.models.sync_key import KeyPair from boards.models.signature import GlobalId, Signature -from boards.models.sync_key import KeyPair from boards.models.image import PostImage from boards.models.attachment import Attachment from boards.models.thread import Thread diff --git a/boards/models/post/sync.py b/boards/models/post/sync.py --- a/boards/models/post/sync.py +++ b/boards/models/post/sync.py @@ -43,6 +43,9 @@ ATTR_MIMETYPE = 'mimetype' ATTR_KEY = 'key' ATTR_REF = 'ref' ATTR_URL = 'url' +ATTR_ID_TYPE = 'id-type' + +ID_TYPE_MD5 = 'md5' STATUS_SUCCESS = 'success' @@ -269,6 +272,7 @@ class SyncManager: mimetype = get_file_mimetype(file) attachment = et.SubElement(tag_attachments, TAG_ATTACHMENT) attachment.set(ATTR_MIMETYPE, mimetype) + attachment.set(ATTR_ID_TYPE, ID_TYPE_MD5) attachment.text = hash attachment_ref = et.SubElement(tag_refs, TAG_ATTACHMENT_REF) diff --git a/boards/models/signature.py b/boards/models/signature.py --- a/boards/models/signature.py +++ b/boards/models/signature.py @@ -1,5 +1,6 @@ import xml.etree.ElementTree as et from django.db import models +from boards.models import KeyPair TAG_MODEL = 'model' @@ -124,6 +125,11 @@ class GlobalId(models.Model): key_type=element.get(ATTR_KEY_TYPE), local_id=int(element.get(ATTR_LOCAL_ID))), False + def is_local(self): + """Checks fo the ID is local model's""" + return KeyPair.objects.filter( + key_type=self.key_type, public_key=self.key).exists() + class Signature(models.Model): class Meta: