From ae27acf1f9f811088c96664faa398315b5eca96d Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Thu, 19 Jan 2017 12:10:35 +0100 Subject: [PATCH] Backwards incompatible: django-mptt removal. Removal of django-mptt and therefor the removal of a tree based snippet list, due to performance reasons with large snippet counts. Snippets still have a 'parent' relation if it's an answer of another snippet, however this is no longer a Nested Set. The UI is simplified too and the user can now only compare an answer to it's parent snippet. I believe this is the major use case anyway. --- dpaste/migrations/0002_auto_20170119_1038.py | 31 +++++++++ dpaste/models.py | 7 -- dpaste/settings/base.py | 1 - dpaste/templates/dpaste/snippet_details.html | 73 +++++--------------- dpaste/templates/dpaste/snippet_diff.html | 3 +- dpaste/views.py | 4 -- runtests.py | 1 - setup.py | 1 - 8 files changed, 52 insertions(+), 69 deletions(-) create mode 100644 dpaste/migrations/0002_auto_20170119_1038.py diff --git a/dpaste/migrations/0002_auto_20170119_1038.py b/dpaste/migrations/0002_auto_20170119_1038.py new file mode 100644 index 0000000..aced2eb --- /dev/null +++ b/dpaste/migrations/0002_auto_20170119_1038.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-01-19 10:38 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('dpaste', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='snippet', + name='level', + ), + migrations.RemoveField( + model_name='snippet', + name='lft', + ), + migrations.RemoveField( + model_name='snippet', + name='rght', + ), + migrations.RemoveField( + model_name='snippet', + name='tree_id', + ), + ] diff --git a/dpaste/models.py b/dpaste/models.py index e9da20b..cf745f8 100644 --- a/dpaste/models.py +++ b/dpaste/models.py @@ -1,6 +1,5 @@ from random import SystemRandom -import mptt from django.conf import settings from django.core.urlresolvers import reverse from django.db import models @@ -62,10 +61,6 @@ class Snippet(models.Model): return remaining > 0 and remaining or 0 return None - @property - def is_single(self): - return self.is_root_node() and not self.get_children() - def save(self, *args, **kwargs): if not self.secret_id: self.secret_id = generate_secret_id() @@ -76,5 +71,3 @@ class Snippet(models.Model): def __unicode__(self): return self.secret_id - -mptt.register(Snippet, order_insertion_by=['content']) diff --git a/dpaste/settings/base.py b/dpaste/settings/base.py index 142b99c..43658df 100644 --- a/dpaste/settings/base.py +++ b/dpaste/settings/base.py @@ -114,7 +114,6 @@ TEMPLATES = [ INSTALLED_APPS = ( 'django.contrib.staticfiles', 'django.contrib.sessions', - 'mptt', 'gunicorn', 'dpaste', ) diff --git a/dpaste/templates/dpaste/snippet_details.html b/dpaste/templates/dpaste/snippet_details.html index e6d3283..6f4e54b 100644 --- a/dpaste/templates/dpaste/snippet_details.html +++ b/dpaste/templates/dpaste/snippet_details.html @@ -1,6 +1,5 @@ {% extends "dpaste/base.html" %} -{% load mptt_tags %} {% load i18n %} {% load dpaste_tags %} @@ -21,34 +20,9 @@ ======================================================================= -->
-
+
-
-
- {% csrf_token %} -
- {% for tree_item,structure in tree|tree_info %} - {% if structure.new_level %}
  • {% else %}
  • {% endif %} -
    - - - - - {% ifequal snippet tree_item %} - #{{ tree_item.id }} - {% else %} - #{{ tree_item.id }} - {% endifequal %} -
    - {% for level in structure.closed_levels %}
{% endfor %} - {% endfor %} -
- -
-
-
-
@@ -68,8 +42,8 @@ {% if snippet.pk|in_list:request.session.snippet_list %} {% trans "Delete Now" %} {% endif %} - {% if not snippet.is_single %} - {% trans "Compare Snippets" %} + {% if snippet.parent %} + {% trans "Compare this Answer" %} {% endif %} {% if snippet.expire_type != 3 %} {% trans "View Raw" %} @@ -125,21 +99,15 @@ jQuery(function($) { $(this).removeClass('snippet-reply-hidden'); }); + var curLine = document.location.hash; + + {% if snippet.parent %} /* ------------------------------------------------------------------------ Diff Ajax Call ------------------------------------------------------------------------ */ - var diffReq; - - $('.snippet-diff-trigger').click(function(e) { - e.preventDefault(); - $('#snippet-diff').slideDown('fast'); - $('#snippet-diff form').submit(); - }); - - - $('#diffform').submit(function() { - var a = $('input[name="a"]:checked').val(), - b = $('input[name="b"]:checked').val(); + function fetchDiff() { + var a = {{ snippet.parent.pk }}, + b = {{ snippet.pk }}; window.location.hash = 'D' + a + ',' + b; @@ -156,23 +124,20 @@ jQuery(function($) { }).complete(function() { diffReq = null; }); + } - return false; + var diffReq; + $('.snippet-diff-trigger').click(function(e) { + e.preventDefault(); + fetchDiff(); + $('#snippet-diff').slideDown('fast'); }); - var curLine = document.location.hash, - hashlist; - if (curLine.substring(0, 2) === '#D') { - hashlist = curLine.substring(2).split(','); - if (hashlist.length === 2) { - console.log(hashlist); - $('#diffform input[name="a"][value="' + hashlist[0] + '"]').prop('checked', true); - $('#diffform input[name="b"][value="' + hashlist[1] + '"]').prop('checked', true); - $('#snippet-diff').slideDown('fast'); - $('#snippet-diff form').submit(); - } + fetchDiff(); + $('#snippet-diff').slideDown('fast'); } + {% endif %} /* ------------------------------------------------------------------------ Line Highlighting @@ -201,7 +166,7 @@ jQuery(function($) { }); /* ------------------------------------------------------------------------ - Line Highlighting + Wordwrap ------------------------------------------------------------------------ */ $('#toggleWordwrap').click(function(e){ e.preventDefault(); diff --git a/dpaste/templates/dpaste/snippet_diff.html b/dpaste/templates/dpaste/snippet_diff.html index 649131c..34a7f6f 100644 --- a/dpaste/templates/dpaste/snippet_diff.html +++ b/dpaste/templates/dpaste/snippet_diff.html @@ -2,7 +2,8 @@

{% blocktrans with fileA.get_absolute_url as filea_url and fileB.get_absolute_url as fileb_url and fileA.id as filea_id and fileB.id as fileb_id %} - Diff between #{{ filea_id }} and #{{ fileb_id }} + Difference between this answer #{{ fileb_id }} + and the parent snippet #{{ filea_id }} {% endblocktrans %}

diff --git a/dpaste/views.py b/dpaste/views.py index b48fdb6..b7bf4d0 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -65,9 +65,6 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h snippet.view_count += 1 snippet.save() - tree = snippet.get_root() - tree = tree.get_descendants(include_self=True) - new_snippet_initial = { 'content': snippet.content, 'lexer': snippet.lexer, @@ -92,7 +89,6 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h 'snippet': snippet, 'lexers': LEXER_LIST, 'lines': range(snippet.get_linecount()), - 'tree': tree, 'wordwrap': snippet.lexer in LEXER_WORDWRAP and 'True' or 'False', 'gist': getattr(settings, 'DPASTE_ENABLE_GIST', True), } diff --git a/runtests.py b/runtests.py index 2338e5b..a42d256 100755 --- a/runtests.py +++ b/runtests.py @@ -32,7 +32,6 @@ SETTINGS = { 'INSTALLED_APPS': [ 'django.contrib.sessions', 'django.contrib.staticfiles', - 'mptt', 'dpaste', ], 'MIDDLEWARE_CLASSES': ( diff --git a/setup.py b/setup.py index 0ce080d..d29d36a 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,6 @@ setup( include_package_data=True, install_requires=[ 'django>=1.8', - 'django-mptt>=0.8.3', 'pygments>=1.6', 'requests>=2.0.0', ],