Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
meanspec-hwinfo-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MeanSpec (SCE338 2024-2 Group 1)
meanspec-hwinfo-daemon
Commits
e29240f2
Verified
Commit
e29240f2
authored
5 months ago
by
Eunhak Lee
Browse files
Options
Downloads
Patches
Plain Diff
feat: 이미 parts 들이 등록돼있는 경우 조합을 재활용 함
parent
77b51371
No related branches found
No related tags found
No related merge requests found
Pipeline
#10924
passed
5 months ago
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
push_to_db.py
+41
-12
41 additions, 12 deletions
push_to_db.py
with
41 additions
and
12 deletions
push_to_db.py
+
41
−
12
View file @
e29240f2
...
...
@@ -73,6 +73,20 @@ RETURNING part_id;""".format(type=_part_type_enum, columns=columns, value_entrie
return
None
def
check_if_parts_exist
(
_cursor
,
_user_id
,
_part_ids
):
sql
=
"""
WITH result AS (SELECT combinations.id AS combination_id,
ARRAY(SELECT part_id FROM relations WHERE relations.combination_id = combinations.id ORDER BY relations.part_id) AS parts
FROM combinations WHERE combinations.owner_id = %s) SELECT combination_id FROM result WHERE parts = %s;
"""
_cursor
.
execute
(
sql
,
(
_user_id
,
_part_ids
))
data
=
_cursor
.
fetchall
()
if
not
data
:
return
None
_existing_combination_id
=
data
[
-
1
][
-
1
]
return
_existing_combination_id
def
create_combination
(
_cursor
,
nickname
,
_user_id
):
_pc_name
=
"
새 PC
"
if
nickname
:
...
...
@@ -140,6 +154,7 @@ def func():
_parts
=
parse
.
handle_xml_body
(
_xml_document
)
_part_ids
=
[]
_created_parts
=
False
print
(
"
Matching parts
"
)
...
...
@@ -157,6 +172,7 @@ def func():
_matched_id
=
match_part_obj_into_db
(
part
,
part_type
)
if
not
_matched_id
:
# DB에 없는 부품이라면
_created_parts
=
True
print
(
"
.. creating new part with
"
,
part
[
"
name
"
])
with
db_conn
.
cursor
()
as
cursor
:
_matched_id
=
create_new_one
(
part
,
part_type
,
cursor
)
...
...
@@ -167,21 +183,34 @@ def func():
continue
print
(
f
"
[WARNING] failed to match part type=
{
part_type
}
, part:
"
,
part
,
file
=
sys
.
stderr
)
print
(
"
Creating combination
"
)
with
db_conn
.
cursor
()
as
cursor
:
_combination_id
=
create_combination
(
cursor
,
None
,
_user_id
)
if
not
_combination_id
:
print
(
"
Failed to create combination
"
,
file
=
sys
.
stderr
)
exit
(
1
)
print
(
"
Wiring parts
"
,
_part_ids
,
"
to combination id
"
,
_combination_id
)
with
db_conn
.
cursor
()
as
cursor
:
wire_part_to_combination
(
cursor
,
_combination_id
,
*
_part_ids
)
_combination_id
=
None
# 이미 존재하는 경우
if
not
_created_parts
:
print
(
"
Checking combination existance
"
)
with
db_conn
.
cursor
()
as
cursor
:
_combination_id
=
check_if_parts_exist
(
cursor
,
_user_id
,
_part_ids
)
print
(
"
Committing to DB
"
)
db_conn
.
commit
()
if
_combination_id
is
not
None
:
print
(
"
Combination exist. Using combination id
"
,
_combination_id
)
# 새로 추가하는 경우
if
_combination_id
is
not
None
:
print
(
"
Creating combination
"
)
with
db_conn
.
cursor
()
as
cursor
:
_combination_id
=
create_combination
(
cursor
,
None
,
_user_id
)
if
not
_combination_id
:
print
(
"
Failed to create combination
"
,
file
=
sys
.
stderr
)
exit
(
1
)
print
(
"
Wiring parts
"
,
_part_ids
,
"
to combination id
"
,
_combination_id
)
with
db_conn
.
cursor
()
as
cursor
:
wire_part_to_combination
(
cursor
,
_combination_id
,
*
_part_ids
)
print
(
"
Committing to DB
"
)
db_conn
.
commit
()
print
(
"
Finalizing transaction
"
)
with
db_conn
.
cursor
()
as
cursor
:
...
...
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