mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	move the two post bulk edit tasks into one
This commit is contained in:
		| @@ -18,11 +18,7 @@ def set_correspondent(doc_ids, correspondent): | ||||
|     qs.update(correspondent=correspondent) | ||||
|  | ||||
|     async_task( | ||||
|         "documents.tasks.bulk_index_documents", | ||||
|         document_ids=affected_docs | ||||
|     ) | ||||
|  | ||||
|     async_task("documents.tasks.bulk_rename_files", document_ids=affected_docs) | ||||
|         "documents.tasks.bulk_update_documents", document_ids=affected_docs) | ||||
|  | ||||
|     return "OK" | ||||
|  | ||||
| @@ -37,11 +33,7 @@ def set_document_type(doc_ids, document_type): | ||||
|     qs.update(document_type=document_type) | ||||
|  | ||||
|     async_task( | ||||
|         "documents.tasks.bulk_index_documents", | ||||
|         document_ids=affected_docs | ||||
|     ) | ||||
|  | ||||
|     async_task("documents.tasks.bulk_rename_files", document_ids=affected_docs) | ||||
|         "documents.tasks.bulk_update_documents", document_ids=affected_docs) | ||||
|  | ||||
|     return "OK" | ||||
|  | ||||
| @@ -59,11 +51,7 @@ def add_tag(doc_ids, tag): | ||||
|     ]) | ||||
|  | ||||
|     async_task( | ||||
|         "documents.tasks.bulk_index_documents", | ||||
|         document_ids=affected_docs | ||||
|     ) | ||||
|  | ||||
|     async_task("documents.tasks.bulk_rename_files", document_ids=affected_docs) | ||||
|         "documents.tasks.bulk_update_documents", document_ids=affected_docs) | ||||
|  | ||||
|     return "OK" | ||||
|  | ||||
| @@ -81,11 +69,7 @@ def remove_tag(doc_ids, tag): | ||||
|     ).delete() | ||||
|  | ||||
|     async_task( | ||||
|         "documents.tasks.bulk_index_documents", | ||||
|         document_ids=affected_docs | ||||
|     ) | ||||
|  | ||||
|     async_task("documents.tasks.bulk_rename_files", document_ids=affected_docs) | ||||
|         "documents.tasks.bulk_update_documents", document_ids=affected_docs) | ||||
|  | ||||
|     return "OK" | ||||
|  | ||||
| @@ -107,10 +91,7 @@ def modify_tags(doc_ids, add_tags, remove_tags): | ||||
|     ], ignore_conflicts=True) | ||||
|  | ||||
|     async_task( | ||||
|         "documents.tasks.bulk_index_documents", | ||||
|         document_ids=affected_docs | ||||
|     ) | ||||
|     async_task("documents.tasks.bulk_rename_files", document_ids=affected_docs) | ||||
|         "documents.tasks.bulk_update_documents", document_ids=affected_docs) | ||||
|  | ||||
|     return "OK" | ||||
|  | ||||
|   | ||||
| @@ -90,16 +90,11 @@ def sanity_check(): | ||||
|         return "No issues detected." | ||||
|  | ||||
|  | ||||
| def bulk_rename_files(document_ids): | ||||
|     qs = Document.objects.filter(id__in=document_ids) | ||||
|     for doc in qs: | ||||
|         post_save.send(Document, instance=doc, created=False) | ||||
|  | ||||
|  | ||||
| def bulk_index_documents(document_ids): | ||||
| def bulk_update_documents(document_ids): | ||||
|     documents = Document.objects.filter(id__in=document_ids) | ||||
|  | ||||
|     ix = index.open_index() | ||||
|     with AsyncWriter(ix) as writer: | ||||
|         for doc in documents: | ||||
|             index.update_document(writer, doc) | ||||
|             post_save.send(Document, instance=doc, created=False) | ||||
|   | ||||
| @@ -699,49 +699,49 @@ class TestBulkEdit(DirectoriesMixin, APITestCase): | ||||
|         self.assertEqual(Document.objects.filter(correspondent=self.c2).count(), 1) | ||||
|         bulk_edit.set_correspondent([self.doc1.id, self.doc2.id, self.doc3.id], self.c2.id) | ||||
|         self.assertEqual(Document.objects.filter(correspondent=self.c2).count(), 3) | ||||
|         self.assertEqual(self.async_task.call_count, 2) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc1.id, self.doc2.id]) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc1.id, self.doc2.id]) | ||||
|         self.async_task.assert_called_once() | ||||
|         args, kwargs = self.async_task.call_args | ||||
|         self.assertCountEqual(kwargs['document_ids'], [self.doc1.id, self.doc2.id]) | ||||
|  | ||||
|     def test_unset_correspondent(self): | ||||
|         self.assertEqual(Document.objects.filter(correspondent=self.c2).count(), 1) | ||||
|         bulk_edit.set_correspondent([self.doc1.id, self.doc2.id, self.doc3.id], None) | ||||
|         self.assertEqual(Document.objects.filter(correspondent=self.c2).count(), 0) | ||||
|         self.assertEqual(self.async_task.call_count, 2) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc2.id, self.doc3.id]) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc2.id, self.doc3.id]) | ||||
|         self.async_task.assert_called_once() | ||||
|         args, kwargs = self.async_task.call_args | ||||
|         self.assertCountEqual(kwargs['document_ids'], [self.doc2.id, self.doc3.id]) | ||||
|  | ||||
|     def test_set_document_type(self): | ||||
|         self.assertEqual(Document.objects.filter(document_type=self.dt2).count(), 1) | ||||
|         bulk_edit.set_document_type([self.doc1.id, self.doc2.id, self.doc3.id], self.dt2.id) | ||||
|         self.assertEqual(Document.objects.filter(document_type=self.dt2).count(), 3) | ||||
|         self.assertEqual(self.async_task.call_count, 2) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc1.id, self.doc2.id]) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc1.id, self.doc2.id]) | ||||
|         self.async_task.assert_called_once() | ||||
|         args, kwargs = self.async_task.call_args | ||||
|         self.assertCountEqual(kwargs['document_ids'], [self.doc1.id, self.doc2.id]) | ||||
|  | ||||
|     def test_unset_document_type(self): | ||||
|         self.assertEqual(Document.objects.filter(document_type=self.dt2).count(), 1) | ||||
|         bulk_edit.set_document_type([self.doc1.id, self.doc2.id, self.doc3.id], None) | ||||
|         self.assertEqual(Document.objects.filter(document_type=self.dt2).count(), 0) | ||||
|         self.assertEqual(self.async_task.call_count, 2) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc2.id, self.doc3.id]) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc2.id, self.doc3.id]) | ||||
|         self.async_task.assert_called_once() | ||||
|         args, kwargs = self.async_task.call_args | ||||
|         self.assertCountEqual(kwargs['document_ids'], [self.doc2.id, self.doc3.id]) | ||||
|  | ||||
|     def test_add_tag(self): | ||||
|         self.assertEqual(Document.objects.filter(tags__id=self.t1.id).count(), 2) | ||||
|         bulk_edit.add_tag([self.doc1.id, self.doc2.id, self.doc3.id, self.doc4.id], self.t1.id) | ||||
|         self.assertEqual(Document.objects.filter(tags__id=self.t1.id).count(), 4) | ||||
|         self.assertEqual(self.async_task.call_count, 2) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc1.id, self.doc3.id]) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc1.id, self.doc3.id]) | ||||
|         self.async_task.assert_called_once() | ||||
|         args, kwargs = self.async_task.call_args | ||||
|         self.assertCountEqual(kwargs['document_ids'], [self.doc1.id, self.doc3.id]) | ||||
|  | ||||
|     def test_remove_tag(self): | ||||
|         self.assertEqual(Document.objects.filter(tags__id=self.t1.id).count(), 2) | ||||
|         bulk_edit.remove_tag([self.doc1.id, self.doc3.id, self.doc4.id], self.t1.id) | ||||
|         self.assertEqual(Document.objects.filter(tags__id=self.t1.id).count(), 1) | ||||
|         self.assertEqual(self.async_task.call_count, 2) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc4.id]) | ||||
|         self.assertCountEqual(self.async_task.call_args_list[0][1]['document_ids'], [self.doc4.id]) | ||||
|         self.async_task.assert_called_once() | ||||
|         args, kwargs = self.async_task.call_args | ||||
|         self.assertCountEqual(kwargs['document_ids'], [self.doc4.id]) | ||||
|  | ||||
|     def test_modify_tags(self): | ||||
|         tag_unrelated = Tag.objects.create(name="unrelated") | ||||
| @@ -752,6 +752,11 @@ class TestBulkEdit(DirectoriesMixin, APITestCase): | ||||
|         self.assertCountEqual(list(self.doc2.tags.all()), [self.t2, tag_unrelated]) | ||||
|         self.assertCountEqual(list(self.doc3.tags.all()), [self.t2, tag_unrelated]) | ||||
|  | ||||
|         self.async_task.assert_called_once() | ||||
|         args, kwargs = self.async_task.call_args | ||||
|         # TODO: doc3 should not be affected, but the query for that is rather complicated | ||||
|         self.assertCountEqual(kwargs['document_ids'], [self.doc2.id, self.doc3.id]) | ||||
|  | ||||
|     def test_delete(self): | ||||
|         self.assertEqual(Document.objects.count(), 5) | ||||
|         bulk_edit.delete([self.doc1.id, self.doc2.id]) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler