SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SciPost
SciPost
Commits
2977847a
Commit
2977847a
authored
6 years ago
by
Jean-Sébastien Caux
Browse files
Options
Downloads
Patches
Plain Diff
Renew attempt at haystack reindex via celery
parent
b4e118ea
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SciPost_v1/signalprocessors.py
+14
-24
14 additions, 24 deletions
SciPost_v1/signalprocessors.py
with
14 additions
and
24 deletions
SciPost_v1/signalprocessors.py
+
14
−
24
View file @
2977847a
...
@@ -4,7 +4,7 @@ __license__ = "AGPL v3"
...
@@ -4,7 +4,7 @@ __license__ = "AGPL v3"
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.models
import
ContentType
from
haystack
import
signals
from
haystack
import
connection_router
,
connections
,
signals
from
haystack.exceptions
import
NotHandled
from
haystack.exceptions
import
NotHandled
from
SciPost_v1.celery
import
app
from
SciPost_v1.celery
import
app
...
@@ -13,14 +13,11 @@ from submissions.models import Submission
...
@@ -13,14 +13,11 @@ from submissions.models import Submission
@app.task
(
name
=
'
signalprocessors.remove_object_indexes
'
)
@app.task
(
name
=
'
signalprocessors.remove_object_indexes
'
)
def
remove_objects_indexes
(
processor_type_id
,
processor_id
,
def
remove_objects_indexes
(
sender_type_id
,
object_type_id
,
object_id
):
sender_type_id
,
object_type_id
,
object_id
):
"""
"""
Given a set of `objects` model instances, remove them from the index as preparation
Given a set of `objects` model instances, remove them from the index as preparation
for the new index.
for the new index.
"""
"""
processor_type
=
ContentType
.
objects
.
get_for_id
(
processor_type_id
)
processor
=
processor_type
.
get_object_for_this_type
(
pk
=
processor_id
)
sender
=
ContentType
.
objects
.
get_for_id
(
sender_type_id
)
sender
=
ContentType
.
objects
.
get_for_id
(
sender_type_id
)
object_type
=
ContentType
.
objects
.
get_for_id
(
object_type_id
)
object_type
=
ContentType
.
objects
.
get_for_id
(
object_type_id
)
instance
=
object_type
.
get_object_for_this_type
(
pk
=
object_id
)
instance
=
object_type
.
get_object_for_this_type
(
pk
=
object_id
)
...
@@ -37,7 +34,7 @@ def remove_objects_indexes(processor_type_id, processor_id,
...
@@ -37,7 +34,7 @@ def remove_objects_indexes(processor_type_id, processor_id,
objects
=
[
instance
]
objects
=
[
instance
]
try
:
try
:
using_backends
=
processor
.
connection_router
.
for_write
(
instance
=
objects
[
0
])
using_backends
=
connection_router
.
for_write
(
instance
=
objects
[
0
])
except
IndexError
:
except
IndexError
:
# No submissions given, stop processing here
# No submissions given, stop processing here
return
None
return
None
...
@@ -45,7 +42,7 @@ def remove_objects_indexes(processor_type_id, processor_id,
...
@@ -45,7 +42,7 @@ def remove_objects_indexes(processor_type_id, processor_id,
for
instance
in
objects
:
for
instance
in
objects
:
for
using
in
using_backends
:
for
using
in
using_backends
:
try
:
try
:
index
=
processor
.
connections
[
using
].
get_unified_index
().
get_index
(
sender
)
index
=
connections
[
using
].
get_unified_index
().
get_index
(
sender
)
index
.
remove_object
(
instance
,
using
=
using
)
index
.
remove_object
(
instance
,
using
=
using
)
except
NotHandled
:
except
NotHandled
:
# TODO: Maybe log it or let the exception bubble?
# TODO: Maybe log it or let the exception bubble?
...
@@ -53,26 +50,23 @@ def remove_objects_indexes(processor_type_id, processor_id,
...
@@ -53,26 +50,23 @@ def remove_objects_indexes(processor_type_id, processor_id,
@app.task
(
name
=
'
signalprocessors.update_instance_indexes
'
)
@app.task
(
name
=
'
signalprocessors.update_instance_indexes
'
)
def
update_instance_indexes
(
processor_type_id
,
processor_id
,
def
update_instance_indexes
(
sender_type_id
,
object_type_id
,
object_id
):
sender_type_id
,
object_type_id
,
object_id
):
"""
"""
Given an individual model instance, update its entire indexes.
Given an individual model instance, update its entire indexes.
"""
"""
processor_type
=
ContentType
.
objects
.
get_for_id
(
processor_type_id
)
processor
=
processor_type
.
get_object_for_this_type
(
pk
=
processor_id
)
sender
=
ContentType
.
objects
.
get_for_id
(
sender_type_id
)
sender
=
ContentType
.
objects
.
get_for_id
(
sender_type_id
)
object_type
=
ContentType
.
objects
.
get_for_id
(
object_type_id
)
object_type
=
ContentType
.
objects
.
get_for_id
(
object_type_id
)
instance
=
object_type
.
get_object_for_this_type
(
pk
=
object_id
)
instance
=
object_type
.
get_object_for_this_type
(
pk
=
object_id
)
try
:
try
:
using_backends
=
processor
.
connection_router
.
for_write
(
instance
=
instance
)
using_backends
=
connection_router
.
for_write
(
instance
=
instance
)
except
IndexError
:
except
IndexError
:
# No valid instance given, stop processing here
# No valid instance given, stop processing here
return
None
return
None
for
using
in
using_backends
:
for
using
in
using_backends
:
try
:
try
:
index
=
processor
.
connections
[
using
].
get_unified_index
().
get_index
(
sender
)
index
=
connections
[
using
].
get_unified_index
().
get_index
(
sender
)
index
.
update
(
using
=
using
)
index
.
update
(
using
=
using
)
except
NotHandled
:
except
NotHandled
:
# TODO: Maybe log it or let the exception bubble?
# TODO: Maybe log it or let the exception bubble?
...
@@ -82,14 +76,10 @@ def update_instance_indexes(processor_type_id, processor_id,
...
@@ -82,14 +76,10 @@ def update_instance_indexes(processor_type_id, processor_id,
class
AutoSearchIndexingProcessor
(
signals
.
RealtimeSignalProcessor
):
class
AutoSearchIndexingProcessor
(
signals
.
RealtimeSignalProcessor
):
def
handle_save
(
self
,
sender
,
instance
,
**
kwargs
):
def
handle_save
(
self
,
sender
,
instance
,
**
kwargs
):
# if not isinstance(instance, Notification):
if
not
isinstance
(
instance
,
Notification
):
# processor_type_id = ContentType.objects.get_for_model(self).id
sender_type_id
=
ContentType
.
objects
.
get_for_model
(
sender
).
id
# sender_type_id = ContentType.objects.get_for_model(sender).id
instance_type_id
=
ContentType
.
objects
.
get_for_model
(
instance
).
id
# instance_type_id = ContentType.objects.get_for_model(instance).id
chain
=
(
# chain = (
remove_objects_indexes
.
s
(
sender_type_id
,
instance_type_id
,
instance
.
id
)
# remove_objects_indexes.s(processor_type_id, self.id,
|
update_instance_indexes
.
s
(
sender_type_id
,
instance_type_id
,
instance
.
id
))
# sender_type_id, instance_type_id, instance.id)
chain
()
# | update_instance_indexes.s(processor_type_id, self.id,
# sender_type_id, instance_type_id, instance.id))
# chain()
pass
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment