From 909f202136fd2f235b923ea2a9c480106d92f517 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Sun, 12 Mar 2017 15:39:32 +0100 Subject: Split document content into its own table to avoid having to load it each time. Move document creation into the model --- archivist/cli.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'archivist/cli.py') diff --git a/archivist/cli.py b/archivist/cli.py index b10e11b..31646aa 100644 --- a/archivist/cli.py +++ b/archivist/cli.py @@ -237,8 +237,10 @@ def doc(): def add_doc(file, tags, create_tags, ignore_missing_tags): """Add a new document together with the given tags.""" - from .model import Document, Tag, db, DocumentTag + from .model import db, Document + import magic + mimetype = magic.from_file(file.name, mime=True) with db.atomic(): if tags: @@ -247,15 +249,7 @@ def add_doc(file, tags, create_tags, ignore_missing_tags): else: tags = fetch_tags(tags, ignore_missing_tags) - mimetype = magic.from_file(file.name, mime=True) - - doc = Document.create(content = file.read(), - file_type = mimetype, - original_path = file.name, - direction = Document.Direction.IN) - - for t in tags: - DocumentTag.create(document = doc, tag = t) + Document.create_from_file(file, tags, direction = Document.Direction.IN, file_type = mimetype) @doc.command('find') @click.argument('tags', type=TAG, nargs=-1) -- cgit v1.2.3-54-g00ecf