Skip to content

Commit 1bcb1ab

Browse files
committed
feat: updated soft delete functionality
1 parent 43cf9f6 commit 1bcb1ab

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

forum/backends/mongodb/comments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def soft_delete(self, comment_id: str, user_id: str) -> int:
415415

416416
# Update Elasticsearch index
417417
if result.modified_count > 0:
418-
from forum.search.es import ElasticsearchDocumentBackend
418+
from forum.search.es import ElasticsearchDocumentBackend # pylint: disable=import-outside-toplevel
419419

420420
es_backend = ElasticsearchDocumentBackend()
421421
es_backend.update_document(
@@ -441,7 +441,7 @@ def restore(self, comment_id: str) -> int:
441441

442442
# Update Elasticsearch index
443443
if result.modified_count > 0:
444-
from forum.search.es import ElasticsearchDocumentBackend
444+
from forum.search.es import ElasticsearchDocumentBackend # pylint: disable=import-outside-toplevel
445445

446446
es_backend = ElasticsearchDocumentBackend()
447447
es_backend.update_document(

forum/backends/mongodb/threads.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ def delete(self, _id: str) -> int:
2424
get_handler_by_name("comment_thread_deleted").send(
2525
sender=self.__class__, comment_thread_id=_id
2626
)
27-
from forum.backends.mongodb.users import Users
28-
2927
Users().delete_read_state_by_thread_id(_id)
3028
return result
3129

@@ -323,29 +321,27 @@ def soft_delete(self, thread_id: str, user_id: str) -> int:
323321

324322
# Cascade soft delete to all comments of this thread
325323
if result.modified_count > 0:
326-
from forum.backends.mongodb.comments import Comment
324+
from forum.backends.mongodb.comments import Comment # pylint: disable=import-outside-toplevel,cyclic-import
327325
Comment().soft_delete_by_thread(thread_id, user_id)
328326

329327
# Delete read states from user model
330328
if result.modified_count > 0:
331-
from forum.backends.mongodb.users import Users
332329
Users().delete_read_state_by_thread_id(thread_id)
333330

334331
# Update Elasticsearch index to reflect the soft delete
335332
if result.modified_count > 0:
336333
try:
337-
from forum.search.es import ElasticsearchDocumentBackend
338-
334+
from forum.search.es import ElasticsearchDocumentBackend # pylint: disable=import-outside-toplevel
339335
es_backend = ElasticsearchDocumentBackend()
340336
es_backend.update_document(
341337
index_name=self.index_name,
342338
doc_id=thread_id,
343339
update_data={"is_deleted": True},
344340
)
345-
except Exception as e:
341+
except Exception as e: # pylint: disable=broad-exception-caught
346342
# Log the error but don't fail the soft delete operation
347343
# Elasticsearch updates are not critical for the soft delete to succeed
348-
import logging
344+
import logging # pylint: disable=import-outside-toplevel
349345
log = logging.getLogger(__name__)
350346
log.warning(f"Failed to update Elasticsearch for thread {thread_id}: {e}")
351347

@@ -367,18 +363,17 @@ def restore(self, thread_id: str) -> int:
367363
# Update Elasticsearch index to reflect the restore
368364
if result.modified_count > 0:
369365
try:
370-
from forum.search.es import ElasticsearchDocumentBackend
371-
366+
from forum.search.es import ElasticsearchDocumentBackend # pylint: disable=import-outside-toplevel
372367
es_backend = ElasticsearchDocumentBackend()
373368
es_backend.update_document(
374369
index_name=self.index_name,
375370
doc_id=thread_id,
376371
update_data={"is_deleted": False},
377372
)
378-
except Exception as e:
373+
except Exception as e: # pylint: disable=broad-exception-caught
379374
# Log the error but don't fail the restore operation
380375
# Elasticsearch updates are not critical for the restore to succeed
381-
import logging
376+
import logging # pylint: disable=import-outside-toplevel
382377
log = logging.getLogger(__name__)
383378
log.warning(f"Failed to update Elasticsearch for thread {thread_id}: {e}")
384379

forum/backends/mysql/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,7 @@ def soft_delete_thread(thread_id: str, user_id: str) -> int:
23052305
defaults={'username': f"user_{user_id}"}
23062306
)
23072307
result = thread.soft_delete(user)
2308-
2308+
23092309
if result:
23102310
# Cascade soft delete to all comments in this thread
23112311
Comment.objects.filter(
@@ -2316,10 +2316,10 @@ def soft_delete_thread(thread_id: str, user_id: str) -> int:
23162316
deleted_at=timezone.now(),
23172317
deleted_by=user
23182318
)
2319-
2319+
23202320
# Hard delete subscriptions for this thread
23212321
MySQLBackend.delete_subscriptions_of_a_thread(thread_id)
2322-
2322+
23232323
return 1 if result else 0
23242324
except ObjectDoesNotExist:
23252325
return 0

0 commit comments

Comments
 (0)