-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
story/VOGRE-7 #15
story/VOGRE-7 #15
Changes from 87 commits
d6db439
ee7966e
2d8f1dd
b5ac38b
0daa957
257d6a2
50002d0
b8fdfbc
2036802
9d8c2fe
571835a
7a3167d
cbc0e75
9c3a18d
7875785
10c20f1
afeaa35
dfe83fb
7a86c66
c8f63e3
0b00565
857a7d4
4e40f83
b71ec91
e70c80a
25539a9
c166b18
886aea6
140a943
86a445b
becb10e
bf36114
01d2c98
d85da33
b4857ab
fd782ac
cf77a29
9657134
cb48a59
4c9f124
210c734
3f3d416
216e6cb
8b12b30
ca4a497
b2a038b
d88c44f
859ac9a
63c4884
94b23d7
40f16b2
f0ef866
9e0d4d8
08aa08f
0ba651d
63282ba
8083295
8a5cf40
19207f6
d32e852
c09d999
7b4a4e5
7f6c36b
5a597c6
d4de827
ef34605
432d822
71fd5c8
38a1ec6
e72c33b
2ac467a
a32996a
84e781a
d056567
91c666b
42ea4eb
e29cbce
3f7840c
a3f7376
2719e04
d62cfd8
cb0ffa0
c03e3a3
22cfa8b
802b3cb
f2041ec
3a26b3c
bea39e2
a3a0dc8
1feec8a
36b90e8
11ea9fc
b928c83
3705a91
cfe6e1e
d55084f
21de855
14cd882
25cc5b8
29ef265
9ce5df5
6f59886
fc3873f
250426e
5f5e972
a5a6370
4f64d6d
429b67d
4336950
9c2def5
f6db813
754be0b
c2f1bf4
80530ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is the right approach. It is likely to cause memory issues once there are sufficiently many relationsets. It also seems unnecessary. The only time we care about the readiness of a relation to be submitted is when we want to submit them or maybe when we look at a text. So it really only needs to be checked when the page shows all relations, and then only the relations that are relevant (not all of them). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If we only show the relations that can be submitted, then the user will not be able to see all relations that they have created on the text. Can we still show the relations that cannot be submitted with the disabled checkbox? I'll change the way we check for ready relations. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from django.utils.deprecation import MiddlewareMixin | ||
from annotations.models import RelationSet | ||
from asgiref.sync import async_to_sync, sync_to_async | ||
from django.utils import timezone | ||
from datetime import timedelta | ||
|
||
class CheckRelationSetStatusMiddleware(MiddlewareMixin): | ||
""" | ||
Middleware to ensure that RelationSets are correctly marked as ready to submit. | ||
This middleware runs before each request to check and update the status of | ||
RelationSets. RelationSets must have one of three statuses: | ||
|
||
- 'not_ready': Concepts are not yet resolved or merged. | ||
- 'ready_to_submit': All concepts are resolved and the RelationSet is ready for submission. | ||
- 'submitted': This is handled separately in the submission workflow and does not need to | ||
be updated here. | ||
|
||
The purpose of this middleware is to automate the readiness check and ensure that | ||
RelationSets are always in the correct state before they can be submitted to Quadriga. | ||
""" | ||
|
||
# Cache the last check time to reduce query frequency | ||
last_check_time = None | ||
check_interval = timedelta(minutes=5) # Adjust the interval as needed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs to be configurable through settings |
||
|
||
def process_request(self, request): | ||
""" | ||
Synchronous method called before each request. It triggers the status check | ||
asynchronously, with a rate limit based on `check_interval` to reduce load. | ||
""" | ||
if self.should_run_check(): | ||
async_to_sync(self.check_and_update_relation_sets)() | ||
|
||
def should_run_check(self): | ||
""" | ||
Determines whether the status check should be run based on the defined interval. | ||
""" | ||
current_time = timezone.now() | ||
if not self.last_check_time or (current_time - self.last_check_time) > self.check_interval: | ||
self.last_check_time = current_time | ||
return True | ||
return False | ||
|
||
async def check_and_update_relation_sets(self): | ||
""" | ||
This asynchronous function is responsible for checking and updating the | ||
statuses of RelationSets in bulk. It uses the `update_status` method of | ||
each RelationSet instance to evaluate and adjust their status based on | ||
readiness conditions. | ||
""" | ||
# Fetch RelationSets that need a status check asynchronously | ||
relation_sets = await sync_to_async(list)( | ||
RelationSet.objects.filter(status__in=['not_ready', 'ready_to_submit']) | ||
) | ||
|
||
# Update statuses for each RelationSet using the update_status method from Relationset model | ||
for relation_set in relation_sets: | ||
await sync_to_async(relation_set.update_status)() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2.20 on 2024-10-29 16:52 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('annotations', '0041_delete_importedcitesphereitem'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='relationset', | ||
name='status', | ||
field=models.CharField(choices=[('not_ready', 'Not Ready'), ('ready_to_submit', 'Ready to Submit'), ('submitted', 'Submitted')], default='not_ready', max_length=20), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 2.2.20 on 2024-10-29 18:22 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('annotations', '0042_relationset_status'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='relationset', | ||
name='pending', | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -787,12 +787,15 @@ class RelationSet(models.Model): | |
occursIn = models.ForeignKey('Text', related_name='relationsets', on_delete=models.CASCADE) | ||
"""The text on which this RelationSet is based.""" | ||
|
||
pending = models.BooleanField(default=False) | ||
""" | ||
A :class:`.RelationSet` is pending if it has been selected for submission, | ||
but the submission process has not yet completed. The primary purpose of | ||
this field is to prevent duplicate submissions. | ||
""" | ||
STATUS_CHOICES = [ | ||
('not_ready', 'Not Ready'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the first value here should be defined in constants, so the constants can be used elsewhere (see below) |
||
('ready_to_submit', 'Ready to Submit'), | ||
('submitted', 'Submitted'), | ||
] | ||
|
||
status = models.CharField( | ||
max_length=20, choices=STATUS_CHOICES, default='not_ready' | ||
) | ||
|
||
submitted = models.BooleanField(default=False) | ||
""" | ||
|
@@ -908,6 +911,17 @@ def ready(self): | |
return all(map(criteria, values)) | ||
ready.boolean = True # So that we can display a nifty icon in changelist. | ||
|
||
def update_status(self): | ||
""" | ||
Check if the RelationSet is ready and update the status accordingly. | ||
""" | ||
if self.ready(): # Check readiness based on the concepts | ||
if self.status != 'submitted': # Avoid overriding submitted status | ||
self.status = 'ready_to_submit' | ||
else: | ||
self.status = 'not_ready' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in line 920 and 922 the constants defined above should be sued |
||
self.save() | ||
|
||
def appellations(self): | ||
""" | ||
Get all non-predicate appellations in child :class:`.Relation`\s. | ||
|
@@ -1148,4 +1162,4 @@ class DocumentPosition(models.Model): | |
|
||
If :attr:`.position_type` is :attr:`.WHOLE_DOCUMENT`\, then this can be | ||
blank. | ||
""" | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,3 +199,7 @@ | |
border: 0; | ||
background-color: rgb(250, 250, 250); | ||
} | ||
|
||
.relation-submitted { | ||
border-left: 4px solid #7aef7a; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is something that needs to be set for each project. Every project can have a different collection it submits quadruples to.