src/ldt/ldt/ldt_utils/contentindexer.py
author cavaliet
Wed, 23 Apr 2014 13:00:27 +0200
changeset 1300 7a638196577d
parent 1296 1a24fb79eb11
child 1407 fc9654218d53
permissions -rw-r--r--
v1.53.2 : taggit optimisation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
     1
from StringIO import StringIO
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
     2
from django.contrib.contenttypes.models import ContentType
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
     3
from django.dispatch import receiver
863
3eae57bb42b3 correct ref to tagging settings
ymh <ymh.work@gmail.com>
parents: 852
diff changeset
     4
from ldt import settings
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
     5
from ldt.indexation import object_delete, object_insert, object_run_index
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
     6
from ldt.ldt_utils.events import post_project_save
1074
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
     7
from ldt.ldt_utils.models import Segment, Content, Project
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
     8
from ldt.ldt_utils.stat import update_stat_project, add_annotation_to_stat
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
     9
from ldt.ldt_utils.utils import reduce_text_node
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    10
from ldt.utils.url import request_with_auth
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
    11
from taggit.models import Tag, TaggedItem
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
    12
from taggit.utils import parse_tags
863
3eae57bb42b3 correct ref to tagging settings
ymh <ymh.work@gmail.com>
parents: 852
diff changeset
    13
import lxml.etree #@UnresolvedImport
852
393bcc75d26a solve pb with logging and tags
ymh <ymh.work@gmail.com>
parents: 810
diff changeset
    14
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
    15
import logging
852
393bcc75d26a solve pb with logging and tags
ymh <ymh.work@gmail.com>
parents: 810
diff changeset
    16
logger = logging.getLogger(__name__)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    17
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    18
def Property(func):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    19
    return property(**func()) 
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    20
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    21
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    22
class LdtIndexer(object):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    23
    
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    24
    def __init__(self, object_list, decoupage_blackList=settings.DECOUPAGE_BLACKLIST, callback=None):
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    25
        self.__object_list = object_list
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    26
        self.__decoupage_blacklist = decoupage_blackList
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    27
        self.__callback = callback
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    28
        self.__segment_cache = []
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
    29
        self.__all_tags_cache = {}
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
    30
        self.__segment_tags_cache = {}
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
    31
        self.__tags_cache = []
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    32
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    33
    @Property
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    34
    def decoupage_blacklist(): #@NoSelf
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    35
        doc = """get blacklist""" #@UnusedVariable
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    36
       
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    37
        def fget(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    38
            if self.__decoupage_blacklist is None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    39
                self.__decoupage_blacklist = ()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    40
            return self.__decoupage_blacklist
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    41
           
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    42
        def fset(self, value):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    43
            self.__decoupage_blacklist = value
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    44
           
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    45
        def fdel(self):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    46
            del self.__decoupage_blacklist
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    47
           
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    48
        return locals()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    49
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    50
    def index_all(self):
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    51
        for i,obj in enumerate(self.__object_list):
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    52
            if self.__callback:
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    53
                self.__callback(i,obj)
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    54
            self.index_object(obj)
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    55
    
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    56
    
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    57
    def index_object(self, obj):
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    58
        self._do_index_object(obj)
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    59
        
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    60
        if self.__segment_cache:
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    61
            object_insert(Segment, self.__segment_cache, 'id_hash')
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
    62
            object_run_index(Segment, self.__segment_cache)
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    63
            self.__segment_cache = []
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    64
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    65
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    66
    def _do_index_object(self, obj):
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
    67
        raise NotImplementedError()
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    68
    
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    69
    def index_ensemble(self, ensemble, content, project=None):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    70
        ensembleId = ensemble.get(u"id", None)
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
    71
        ctp = ContentType.objects.get_for_model(Segment)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    72
        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    73
        for decoupageNode in ensemble.getchildren():
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    74
            if decoupageNode.tag != "decoupage"  or decoupageNode.get(u"id", None) in self.decoupage_blacklist:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    75
                continue
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    76
            
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    77
            decoupId = decoupageNode.get(u"id", None)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    78
            res = decoupageNode.xpath("elements/element")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    79
            for elementNode in res:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    80
                
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    81
                elementId = elementNode.get(u"id", None)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    82
                tags = elementNode.get(u"tags", None)
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
    83
                
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    84
                if tags is None or len(tags) == 0:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    85
                    tags = u""
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    86
                    restagnode = elementNode.xpath("tag/text()", smart_strings=False)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    87
                    for tagnode in restagnode:
852
393bcc75d26a solve pb with logging and tags
ymh <ymh.work@gmail.com>
parents: 810
diff changeset
    88
                        tags = tags + u"," + tagnode
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    89
                        
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    90
                if tags is None or len(tags) == 0:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    91
                    tags = u""
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    92
                    restagnode = elementNode.xpath("tags/tag/text()", smart_strings=False)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    93
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    94
                    for tagnode in restagnode:
852
393bcc75d26a solve pb with logging and tags
ymh <ymh.work@gmail.com>
parents: 810
diff changeset
    95
                        tags = tags + u"," + tagnode
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    96
                
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    97
                if tags is None:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
    98
                    tags = u""
1046
643a0f1991c0 correct tagging for segment.
cavaliet
parents: 922
diff changeset
    99
                
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   100
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   101
                title = reduce_text_node(elementNode, "title/text()")                
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   102
                abstract = reduce_text_node(elementNode, "abstract/text()")
468
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   103
                polemics = elementNode.xpath('meta/polemics/polemic/text()')
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   104
                
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   105
                author = elementNode.get("author", "")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   106
                start_ts = int(float(elementNode.get("begin", "-1")))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   107
                duration = int(float(elementNode.get("dur", "0")))
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   108
                date_str = elementNode.get("date", "")
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   109
                ldt_id = u""
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   110
                if project:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   111
                    ldt_id = project.ldt_id
810
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   112
                # audio annotation management
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   113
                audio_src = u""
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   114
                audio_href = u""
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   115
                audio_node = elementNode.xpath('audio')
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   116
                if audio_node:
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   117
                    audio_src = audio_node[0].get(u"source", u"")
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   118
                    audio_href = audio_node[0].text
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   119
                
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   120
                seg = Segment.create(content=content,
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   121
                              iri_id=content.iri_id,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   122
                              ensemble_id=ensembleId,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   123
                              cutting_id=decoupId,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   124
                              element_id=elementId,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   125
                              title=title,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   126
                              abstract=abstract,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   127
                              duration=duration,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   128
                              author=author,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   129
                              start_ts=start_ts,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   130
                              date=date_str,
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   131
                              project_obj=project,
810
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   132
                              project_id=ldt_id,
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   133
                              audio_src=audio_src,
e7546394653c add audio annotation to segment api and correct reindex command.
cavaliet
parents: 718
diff changeset
   134
                              audio_href=audio_href)
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   135
                
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   136
                tags = parse_tags(tags)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   137
                self.__segment_tags_cache[seg.id_hash] = tags
468
d1ff0694500b Add polemic properties to contents
verrierj
parents: 467
diff changeset
   138
                seg.polemics = seg.get_polemic(polemics)
1300
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   139
                if settings.LDT_INDEXATION_INSERT_BATCH_SIZE < 2:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   140
                    seg.save()
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   141
                    seg.tags.add(*tags)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   142
                else:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   143
                    self.__segment_cache.append(seg)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   144
                    self.__tags_cache = set( list(self.__tags_cache) + tags)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   145
                    
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   146
                    if not (len(self.__segment_cache)%settings.LDT_INDEXATION_INSERT_BATCH_SIZE):
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   147
                        # First we insert/bulk_create the segments
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   148
                        object_insert(Segment, self.__segment_cache, 'id_hash')
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   149
                        # Filter already existing tags in current dict
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   150
                        for t in list(self.__tags_cache):
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   151
                            if t in self.__all_tags_cache:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   152
                                self.__tags_cache.remove(t)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   153
                        # Filter already existing tags in database
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   154
                        current_tags = Tag.objects.filter(name__in=self.__tags_cache)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   155
                        for t in current_tags:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   156
                            self.__all_tags_cache[t.name] = t
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   157
                            self.__tags_cache.remove(t.name)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   158
                        # If the rest of tags were never in the db, we save them
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   159
                        if len(self.__tags_cache)>0:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   160
                            for t in self.__tags_cache:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   161
                                tag = Tag.objects.create(name=t)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   162
                                self.__all_tags_cache[t] = tag
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   163
                        
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   164
                        # Prepare taggeditems
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   165
                        ti = []
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   166
                        for s in self.__segment_cache:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   167
                            s.tag_list = self.__segment_tags_cache[s.id_hash]
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   168
                            for t in self.__segment_tags_cache[s.id_hash]:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   169
                                ti.append( TaggedItem(tag=self.__all_tags_cache[t], content_type=ctp, object_id=s.pk) )
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   170
                        TaggedItem.objects.bulk_create(ti)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   171
                        object_run_index(Segment, self.__segment_cache)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   172
                        self.__segment_cache = []
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   173
        
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   174
        # last loop if necessary
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   175
        if len(self.__segment_cache) > 0:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   176
            # First we insert/bulk_create the segments
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   177
            object_insert(Segment, self.__segment_cache, 'id_hash')
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   178
            # Filter already existing tags in current dict
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   179
            for t in list(self.__tags_cache):
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   180
                if t in self.__all_tags_cache:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   181
                    self.__tags_cache.remove(t)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   182
            # Filter already existing tags in database
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   183
            current_tags = Tag.objects.filter(name__in=self.__tags_cache)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   184
            for t in current_tags:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   185
                self.__all_tags_cache[t.name] = t
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   186
                self.__tags_cache.remove(t.name)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   187
            # If the rest of tags were never in the db, we save them
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   188
            if len(self.__tags_cache)>0:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   189
                for t in self.__tags_cache:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   190
                    tag = Tag.objects.create(name=t)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   191
                    self.__all_tags_cache[t] = tag
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   192
            
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   193
            # Prepare taggeditems
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   194
            ti = []
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   195
            for s in self.__segment_cache:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   196
                s.tag_list = self.__segment_tags_cache[s.id_hash]
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   197
                for t in self.__segment_tags_cache[s.id_hash]:
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   198
                    ti.append( TaggedItem(tag=self.__all_tags_cache[t], content_type=ctp, object_id=s.pk) )
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   199
            TaggedItem.objects.bulk_create(ti)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   200
            object_run_index(Segment, self.__segment_cache)
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   201
            # End of batch
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   202
            self.__segment_cache = []
7a638196577d v1.53.2 : taggit optimisation
cavaliet
parents: 1296
diff changeset
   203
716
31dc2726ca51 centralise les appel à lucene
ymh <ymh.work@gmail.com>
parents: 628
diff changeset
   204
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   205
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   206
class ContentIndexer(LdtIndexer):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   207
        
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   208
    def _do_index_object(self, obj):
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   209
        
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   210
        content = obj 
628
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   211
        url = content.iri_url()
922
cba34a867804 correct bug on indexation.
ymh <ymh.work@gmail.com>
parents: 896
diff changeset
   212
        _, file_content = request_with_auth(url)
cba34a867804 correct bug on indexation.
ymh <ymh.work@gmail.com>
parents: 896
diff changeset
   213
        doc = lxml.etree.parse(StringIO(file_content)) #@UndefinedVariable
628
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   214
       
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   215
        object_delete(Segment, iri_id=content.iri_id, project_id='')
628
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   216
        
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   217
        res = doc.xpath("/iri/body/ensembles/ensemble")
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   218
628
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   219
        for ensemble in res:                
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   220
            self.index_ensemble(ensemble, content)
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   221
                            
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   222
            
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   223
class ProjectIndexer(LdtIndexer):
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   224
                              
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   225
    def _do_index_object(self, obj):
560
1cb2a4a573e1 correct annoations api handler + ldt encoding
ymh <ymh.work@gmail.com>
parents: 468
diff changeset
   226
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   227
        project = obj
628
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   228
        # pocketfilms.utils.log.debug("Indexing project : "+str(project.iri_id))
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   229
        doc = lxml.etree.fromstring(project.ldt_encoded) #@UndefinedVariable
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   230
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   231
        object_delete(Segment, project_obj__ldt_id=project.ldt_id)
628
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   232
       
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   233
        res = doc.xpath("/iri/annotations/content")
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   234
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   235
        for content in res:
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   236
            contentId = content.get(u"id", None)
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   237
            content_obj = None
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   238
628
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   239
            clist = Content.objects.filter(iri_id = contentId) #@UndefinedVariable
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   240
            if len(clist) > 0:
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   241
                content_obj = clist[0]
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   242
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   243
            for ensemble in content.getchildren():
1f4fd6aed2d0 correct initialization.
ymh <ymh.work@gmail.com>
parents: 602
diff changeset
   244
                self.index_ensemble(ensemble, content_obj, project)
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   245
1072
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   246
@receiver(post_project_save)
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   247
def index_project(**kwargs):
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   248
    must_reindex = kwargs.get("must_reindex", True)
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   249
    if must_reindex and settings.AUTO_INDEX_AFTER_SAVE:
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 103
diff changeset
   250
        instance = kwargs['instance']
1072
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   251
        if instance.state != Project.PUBLISHED:
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   252
            object_delete(Segment, project_obj__ldt_id=instance.ldt_id)
718
5e27a39d3742 replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents: 716
diff changeset
   253
            update_stat_project(instance)
5e27a39d3742 replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents: 716
diff changeset
   254
        else:
5e27a39d3742 replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents: 716
diff changeset
   255
            projectIndexer = ProjectIndexer([instance])
5e27a39d3742 replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents: 716
diff changeset
   256
            projectIndexer.index_all()
5e27a39d3742 replace lucene by haystack, remove references to lucene
ymh <ymh.work@gmail.com>
parents: 716
diff changeset
   257
            update_stat_project(instance)
1072
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   258
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   259
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   260
1074
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   261
def add_segment(params):
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   262
                                
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   263
    project = params.get("project",None)
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   264
    content = params.get("content",None)
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   265
    ensemble_id = params.get("ensemble_id", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   266
    cutting_id = params.get("cutting_id", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   267
    element_id = params.get("element_id", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   268
    title = params.get("title", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   269
    abstract = params.get("abstract", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   270
    tags_str = params.get("tags", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   271
    start_ts = params.get("start_ts", 0)
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   272
    duration = params.get("duration", 0)
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   273
    author = params.get("author", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   274
    date_str = params.get("date", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   275
    audio_src = params.get("audio_src", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   276
    audio_href = params.get("audio_href", "")
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   277
    polemics = params.get("polemics", "")
1072
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   278
    
1117
3bab1e42acfa - update haystack
ymh <ymh.work@gmail.com>
parents: 1074
diff changeset
   279
    seg = Segment.create(content=content,
1074
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   280
              iri_id=content.iri_id if content is not None else "",
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   281
              ensemble_id=ensemble_id,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   282
              cutting_id=cutting_id,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   283
              element_id=element_id,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   284
              title=title,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   285
              abstract=abstract,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   286
              duration=duration,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   287
              author=author,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   288
              start_ts=start_ts,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   289
              date=date_str,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   290
              project_obj=project,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   291
              project_id=project.ldt_id if project is not None else "",
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   292
              audio_src=audio_src,
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   293
              audio_href=audio_href)
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   294
    seg.polemics = seg.get_polemic(polemics)
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   295
    seg.save()
1296
1a24fb79eb11 v1.53 : tagging to taggit migration
cavaliet
parents: 1117
diff changeset
   296
    for t in parse_tags(tags_str):
1a24fb79eb11 v1.53 : tagging to taggit migration
cavaliet
parents: 1117
diff changeset
   297
        seg.tags.add(t)
1a24fb79eb11 v1.53 : tagging to taggit migration
cavaliet
parents: 1117
diff changeset
   298
    seg.save()
1074
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   299
    add_annotation_to_stat(seg.content, seg.start_ts, seg.start_ts+seg.duration)
1072
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   300
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   301
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   302
def delete_segment(project, project_id, iri_id, ensemble_id, cutting_id, element_id):
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   303
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   304
    # delete Segment
1074
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   305
    for seg in Segment.objects.filter(project_id=project_id, iri_id=iri_id, ensemble_id=ensemble_id, cutting_id=cutting_id, element_id=element_id):        
1072
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   306
        seg.delete()
1074
36f657714851 optimize adding an annotation
ymh <ymh.work@gmail.com>
parents: 1072
diff changeset
   307
        add_annotation_to_stat(seg.content, seg.start_ts, seg.start_ts+seg.duration)
1072
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   308
    
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   309
    
687dabdd25a7 Add an argument to project save to avoid indexation
ymh <ymh.work@gmail.com>
parents: 1046
diff changeset
   310