Skip to content

Commit 3aefe30

Browse files
ref migration, add payload to exports
1 parent 1463966 commit 3aefe30

File tree

7 files changed

+77
-7
lines changed

7 files changed

+77
-7
lines changed

backend-app/archive/services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _make_archive(project: Project, request: Request) -> tuple[dict[str, Any], i
4040
attributes = project.attribute_set \
4141
.filter(id__in=request_query.get("attr", [])) \
4242
.order_by("level__order", "id") \
43-
.values("name") \
43+
.only("name") \
4444
.values_list("name", flat=True)
4545

4646
only_new = request_query.get("only_new", False) is True

backend-app/attribute/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ class Meta:
3535

3636
def get_attributes(self, instance: AttributeGroup) -> tuple[tuple[int, int, str]]:
3737
return tuple(
38-
(attr.id, attr.level.order, attr.name)
38+
(attr.id, attr.level.order, attr.name, attr.payload)
3939
for attr in instance.attribute.all()
4040
)

backend-app/file/services.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _get_files(
137137
"attributegroup_set__attribute",
138138
queryset=Attribute.objects.select_related("level")
139139
.order_by("level__order", "level_id")
140-
.only("id", "name", "level__order")
140+
.only("id", "name", "level__order", "payload")
141141
)
142142
) \
143143
.annotate(
@@ -159,6 +159,7 @@ def _get_files(
159159
.filter(attribute__in=attribute_query) \
160160
.annotate(count=Count("uid")) \
161161
.filter(count=len(attribute_query)) \
162+
.only("uid") \
162163
.values("uid")
163164
files = files.filter(attributegroup__in=Subquery(sub_query))
164165
else: files = files.distinct()
@@ -259,8 +260,9 @@ class StatsServices:
259260
"attribute__id",
260261
"attribute__name",
261262
"attribute__parent",
263+
"attribute__payload",
262264
"attribute__attributegroup__file__file_type",
263-
"attribute__attributegroup__file__status"
265+
"attribute__attributegroup__file__status",
264266
)
265267

266268
_USER_QUERY_VALUES: tuple[str, ...] = (
@@ -327,6 +329,7 @@ def from_attribute(cls, project_id: int) -> tuple[list[dict[str, Any]], int]:
327329
"attribute__name": "No attribute",
328330
"attribute__parent": None,
329331
"attribute__id": "no-id",
332+
"attribute__payload": "",
330333
"attribute__attributegroup__file__file_type": entry["file_type"],
331334
"attribute__attributegroup__file__status": entry["status"],
332335
"count": entry["file_count"]

frontend-app/src/components/FilesDownload/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function FilesDownload({ pathID, attributes }) {
5151
data: TYPE_FILTER,
5252
},
5353
{
54-
prettyName: "Date Filter:",
54+
prettyName: "Upload date Filter:",
5555
name: "date",
5656
type: "date",
5757
}

frontend-app/src/components/forms/AttributesForm/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default function AttributesForm({
7272
}
7373
};
7474

75-
const handleLevelDelete = (index, orig, _id) => {
75+
const handleLevelDelete = (index, orig) => {
7676
if (orig) return setAcceptDelete(index);
7777
if (index === 0) deleteForm(formId);
7878
else {

nginx/nginx.conf.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ server {
1212
proxy_buffering off;
1313
client_max_body_size 5000M;
1414
proxy_connect_timeout 60s;
15-
proxy_read_timeout 60s;
15+
proxy_read_timeout 180s;
1616

1717
add_header 'Access-Control-Allow-Origin' $http_origin always;
1818
add_header 'Access-Control-Allow-Credentials' 'true' always;

scripts/project_migrate.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,69 @@
33
from attribute.models import Attribute, Level
44

55

6+
def migrate_third_attrs(target: int, dest: int, from_order: int = 1):
7+
attr_data = File.objects \
8+
.filter(
9+
project_id=dest,
10+
rebound_project=target,
11+
attributegroup__attribute__project_id=target,
12+
attributegroup__attribute__level__order__gte=from_order
13+
) \
14+
.values_list(
15+
"attributegroup__uid",
16+
"attributegroup__attribute__id",
17+
"attributegroup__attribute__name",
18+
"attributegroup__attribute__project_id",
19+
"attributegroup__attribute__level__order"
20+
) \
21+
.distinct()
22+
print(f"[1/4] Found {attr_data.count()} attrs to migrate")
23+
24+
rebound = []
25+
created = 0
26+
failed = []
27+
28+
cache = {}
29+
30+
for ag_id, a_id, a_name, p_id, l_order in attr_data:
31+
ag_id = str(ag_id)
32+
33+
if p_id != target: continue
34+
35+
if (cached := cache.get((a_id, a_name))):
36+
print(f"[2/4] Cached {a_name}")
37+
rebound.append((cached, a_id, ag_id,))
38+
continue
39+
40+
try:
41+
map_id = Attribute.objects.filter(project_id=dest, name=a_name).id
42+
rebound.append((map_id, a_id, ag_id))
43+
cache[(a_id, a_name)] = map_id
44+
print(f"[2/4] Found {a_name} in dest")
45+
except:
46+
levels = Level.objects.filter(project_id=dest, order=l_order)
47+
if levels.count() == 1:
48+
map_id = levels.first().attribute_set.create(name=a_name, project_id=dest).id
49+
rebound.append((map_id, a_id, ag_id))
50+
created += 1
51+
cache[(a_id, a_name)] = map_id
52+
print(f"[2/4] Created {a_name} in dest")
53+
else: failed.append((a_id, a_name))
54+
55+
print(f"[3/4] Got {len(rebound)} attributes with {created} created")
56+
57+
with connection.cursor() as cursor: cursor.executemany(
58+
"""
59+
update attribute_group_attribute
60+
set attribute_id = %s
61+
where attribute_id = %s and attributegroup_id = %s;
62+
""",
63+
rebound
64+
)
65+
66+
print(f"[4/4] Migrate done with {len(failed)} failed")
67+
68+
669
def migrate_files(
770
target_project: int,
871
dest_project: int,
@@ -46,6 +109,7 @@ def get_ids(sep: str, path_from: str, path_to: str) -> tuple[set[str], set[str]]
46109
set([row.split(sep)[0] for row in data_to.split("\n")[1:] if row])
47110
)
48111

112+
49113
def main(target: tuple[int, str], dest: tuple[int, str], sep: str):
50114
target_id, target_file = target
51115
dest_id, dest_file = dest
@@ -83,3 +147,6 @@ def main(target: tuple[int, str], dest: tuple[int, str], sep: str):
83147
.filter(project_id=target_id, attributegroup__attribute__payload__in=target_set) \
84148
.update(rebound_project=target_id, project_id=dest_id)
85149
print(f"[4/4] Rebound {res} total files to the new projects")
150+
151+
152+
# migrate_third_attrs(target_id, dest_id, 1)

0 commit comments

Comments
 (0)