summaryrefslogtreecommitdiff
path: root/issues/sqlalchemy.gmi
blob: a675b851d24e99db91332af0915fb5b70a541d96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Replace sqlalchemy with MySQLdb

## Tags

* assigned: bonfacem, zachs
* type: refactor
* priority: medium

## Description

Connections that use sqlalchemy are the only placen in GN2 where connections remain "open" indefinitely until a connection is closed.  In the event that we have many users at the same time, say like during one of Rob's classes; and they do a search, we have N connections indefinitely open until their sessions are killed.  And removing that is trivial, and to demonstrate that using a random example from GN2 (/wqflask/wqflask/search_results.py):

```
def get_GO_symbols(a_search):
    query = """SELECT genes
	       FROM GORef
	       WHERE goterm='{0}:{1}'""".format(a_search['key'], a_search['search_term'][0])

    gene_list = g.db.execute(query).fetchone()[0].strip().split()

    new_terms = []
    for gene in gene_list:
	this_term = dict(key=None,
			 separator=None,
			 search_term=[gene])

	new_terms.append(this_term)

    return new_terms
```

could be replaced with:

```
 def get_GO_symbols(a_search):
-    query = """SELECT genes
-               FROM GORef
-               WHERE goterm='{0}:{1}'""".format(a_search['key'], a_search['search_term'][0])
-
-    gene_list = g.db.execute(query).fetchone()[0].strip().split()
-
-    new_terms = []
-    for gene in gene_list:
-        this_term = dict(key=None,
-                         separator=None,
-                         search_term=[gene])
-
-        new_terms.append(this_term)
-
-    return new_terms
+    genes = []
+    with database_connection() as conn:
+        with conn.cursor() as cursor:
+            cursor.execute("SELECT genes FROM GORef WHERE goterm=%s",
+                         (a_search.get("key")))
+            genes = cursor.fetchone()[0].strip().split()
+    return [dict(key=None, separator=None, search_term=[gene])
+            for gene in genes]
```

## Resolution

This is has been merged in:

=> https://github.com/genenetwork/genenetwork2/pull/730

Should problems occur, a new issue will be created.

* closed