aboutsummaryrefslogtreecommitdiff
path: root/backend/server.py
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-06-15 17:14:28 +1000
committerTerry Truong <terry06890@gmail.com>2022-06-15 17:14:28 +1000
commit3402f3d6e906afb500b95448d7d0b136b6b5ee86 (patch)
treeced939ea9a2ef9c798bb624a0a809b94ff117192 /backend/server.py
parentfd0cb82ddd065a0a8966b67f98a151adfbab4bc3 (diff)
Adjust 'node_imgs' table to use node name, not id
Diffstat (limited to 'backend/server.py')
-rwxr-xr-xbackend/server.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/backend/server.py b/backend/server.py
index 999da25..e252d5e 100755
--- a/backend/server.py
+++ b/backend/server.py
@@ -55,7 +55,8 @@ def lookupNodes(names, useReducedTree):
nodeObjs[childName]["pSupport"] = (pSupport == 1)
# Get image names
idsToNames = {nodeObjs[n]["otolId"]: n for n in nodeObjs.keys()}
- query = "SELECT id FROM node_imgs WHERE id IN ({})".format(",".join(["?"] * len(idsToNames)))
+ query = "SELECT nodes.id from nodes INNER JOIN node_imgs ON nodes.name = node_imgs.name" \
+ " WHERE nodes.id IN ({})".format(",".join(["?"] * len(idsToNames)))
for (otolId,) in cur.execute(query, list(idsToNames.keys())):
nodeObjs[idsToNames[otolId]]["imgName"] = otolId + ".jpg"
# Get 'linked' images for unresolved names
@@ -136,8 +137,9 @@ def lookupNodeInfo(name, useReducedTree):
otolId = nodeObj["imgName"][:-4] # Convert filename excluding .jpg suffix
print(otolId)
query = "SELECT images.id, images.src, url, license, artist, credit FROM" \
- " node_imgs INNER JOIN images ON node_imgs.img_id = images.id AND node_imgs.src = images.src" \
- " WHERE node_imgs.id = ?"
+ " nodes INNER JOIN node_imgs ON nodes.name = node_imgs.name" \
+ " INNER JOIN images ON node_imgs.img_id = images.id AND node_imgs.src = images.src" \
+ " WHERE nodes.id = ?"
(imgId, imgSrc, url, license, artist, credit) = cur.execute(query, (otolId,)).fetchone()
imgData = {"imgId": imgId, "imgSrc": imgSrc,
"url": url, "license": license, "artist": artist, "credit": credit}
@@ -145,9 +147,10 @@ def lookupNodeInfo(name, useReducedTree):
# Get info for compound-image parts
imgData = [None, None]
idsToLookup = [n[:-4] for n in nodeObj["imgName"] if n != None]
- query = "SELECT node_imgs.id, images.id, images.src, url, license, artist, credit FROM" \
- " node_imgs INNER JOIN images ON node_imgs.img_id = images.id AND node_imgs.src = images.src" \
- " WHERE node_imgs.id IN ({})".format(",".join(["?"] * len(idsToLookup)))
+ query = "SELECT nodes.id, images.id, images.src, url, license, artist, credit FROM" \
+ " nodes INNER JOIN node_imgs ON nodes.name = node_imgs.name" \
+ " INNER JOIN images ON node_imgs.img_id = images.id AND node_imgs.src = images.src" \
+ " WHERE nodes.id IN ({})".format(",".join(["?"] * len(idsToLookup)))
for (imgOtolId, imgId, imgSrc, url, license, artist, credit) in cur.execute(query, idsToLookup):
imgDataVal = {"imgId": imgId, "imgSrc": imgSrc,
"url": url, "license": license, "artist": artist, "credit": credit}