Skip to content

Commit 5c66928

Browse files
committed
a rushed migration to pure-python pymysql, as the new toolforge debian image does not have mysql client libraries installed
1 parent 6d01f01 commit 5c66928

3 files changed

Lines changed: 38 additions & 32 deletions

File tree

requirements_labs.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
-e git+https://github.com/mahmoud/clastic.git#egg=clastic
2-
-e git+https://github.com/slaporte/wapiti.git#egg=wapiti
3-
4-
oursql==0.9.3.1
1+
ashes==19.2.0
2+
attrs==21.4.0
3+
boltons==21.0.0
4+
-e git+https://github.com/mahmoud/clastic.git@2a2612bc5a2f71e894bebbdbf962fdff988130f0#egg=clastic
5+
face==20.1.1
56
flup==1.0.2
7+
glom==22.1.0
8+
PyMySQL==0.10.1
9+
secure-cookie==0.1.0
10+
-e git+https://github.com/slaporte/wapiti.git@e7dc0a7b68305da59e8c46787e5fda6a791c0d1b#egg=wapiti
11+
Werkzeug==1.0.1

weeklypedia/labs/dal.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import time
55
from datetime import datetime, timedelta
6-
import oursql
6+
import pymysql, pymysql.cursors
77

88
from wapiti import WapitiClient
99

@@ -44,32 +44,32 @@ class RecentChangesSummarizer(object):
4444
COUNT(*) AS edits,
4545
COUNT(DISTINCT rc_actor) AS users
4646
FROM recentchanges
47-
WHERE rc_namespace = :namespace
47+
WHERE rc_namespace = %(namespace)s
4848
AND rc_type = 0
49-
AND rc_timestamp > :start_date
49+
AND rc_timestamp > %(start_date)s
5050
GROUP BY page_id
5151
ORDER BY edits
5252
DESC
53-
LIMIT :limit'''
53+
LIMIT %(limit)s'''
5454

5555
_ranked_activity_new_pages_query = '''
5656
SELECT rc_cur_id AS page_id,
5757
rc_title AS title,
5858
COUNT(*) AS edits,
5959
COUNT(DISTINCT rc_actor) AS users
6060
FROM recentchanges
61-
WHERE rc_namespace = :namespace
61+
WHERE rc_namespace = %(namespace)s
6262
AND rc_type = 0
63-
AND rc_timestamp > :start_date
63+
AND rc_timestamp > %(start_date)s
6464
AND rc_cur_id IN (SELECT rc_cur_id
6565
FROM recentchanges
66-
WHERE rc_timestamp > :start_date
67-
AND rc_namespace=:namespace
68-
AND rc_new=:is_new)
66+
WHERE rc_timestamp > %(start_date)s
67+
AND rc_namespace=%(namespace)s
68+
AND rc_new=%(is_new)s)
6969
GROUP BY page_id
7070
ORDER BY edits
7171
DESC
72-
LIMIT :limit'''
72+
LIMIT %(limit)s'''
7373

7474
_bounding_revids_query = '''
7575
SELECT rc_cur_id as page_id,
@@ -81,60 +81,60 @@ class RecentChangesSummarizer(object):
8181
rc_this_oldid,
8282
rc_last_oldid
8383
FROM recentchanges
84-
WHERE rc_namespace = :namespace
85-
AND rc_cur_id = :page_id
84+
WHERE rc_namespace = %(namespace)s
85+
AND rc_cur_id = %(page_id)s
8686
AND rc_type = 0
87-
AND rc_timestamp > :start_date) PageRevs;'''
87+
AND rc_timestamp > %(start_date)s) PageRevs;'''
8888

8989
_activity_query = '''
9090
SELECT COUNT(*) AS edits,
9191
COUNT(DISTINCT rc_actor) AS users,
9292
COUNT(DISTINCT rc_cur_id) AS titles
9393
FROM recentchanges
94-
WHERE rc_namespace = :namespace
94+
WHERE rc_namespace = %(namespace)s
9595
AND rc_type = 0
96-
AND rc_timestamp > :start_date;'''
96+
AND rc_timestamp > %(start_date)s;'''
9797

9898
_anon_activity_query = '''
9999
SELECT COUNT(*) AS anon_edits,
100100
COUNT(DISTINCT actor.actor_name) AS anon_ip_count,
101101
COUNT(DISTINCT rc_cur_id) AS anon_titles
102102
FROM recentchanges
103103
LEFT JOIN actor on rc_actor=actor_id
104-
WHERE rc_namespace = :namespace
104+
WHERE rc_namespace = %(namespace)s
105105
AND rc_type = 0
106-
AND rc_timestamp > :start_date
106+
AND rc_timestamp > %(start_date)s
107107
AND actor.actor_user IS NULL;'''
108108

109109
_bot_activity_query = '''
110110
SELECT COUNT(*) AS bot_edits,
111111
COUNT(DISTINCT rc_actor) AS bot_count,
112112
COUNT(DISTINCT rc_cur_id) AS bot_titles
113113
FROM recentchanges
114-
WHERE rc_namespace = :namespace
114+
WHERE rc_namespace = %(namespace)s
115115
AND rc_type = 0
116-
AND rc_timestamp > :start_date
116+
AND rc_timestamp > %(start_date)s
117117
AND rc_bot=1;'''
118118

119119

120120
def __init__(self, lang='en'):
121121
self.lang = lang
122122
self.db_title = lang + 'wiki_p'
123123
self.db_host = lang + 'wiki.labsdb'
124-
self.connection = oursql.connect(db=self.db_title,
125-
host=self.db_host,
126-
read_default_file=DB_CONFIG_PATH,
127-
charset=None)
124+
self.connection = pymysql.connect(db=self.db_title,
125+
host=self.db_host,
126+
read_default_file=DB_CONFIG_PATH,
127+
charset=None)
128128

129129
def _get_cursor(self):
130-
return self.connection.cursor(oursql.DictCursor)
130+
return self.connection.cursor(pymysql.cursors.DictCursor) # oursql.DictCursor)
131131

132132
def _select(self, query, params=None):
133133
if params is None:
134134
params = []
135-
elif isinstance(params, dict):
136-
old_query, old_params = query, params
137-
query, params = translate_named_param_query(query, params)
135+
#elif isinstance(params, dict):
136+
# old_query, old_params = query, params
137+
# query, params = translate_named_param_query(query, params)
138138
cursor = self._get_cursor()
139139
cursor.execute(query, params)
140140
return cursor.fetchall()

weeklypedia/labs/web_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def create_app():
2424
('/v2/fetch/<lang>', fetch_rc, render_basic),
2525
('/meta', MetaApplication()),
2626
('/_dump_environ', lambda request: request.environ, render_basic)]
27-
return Application(routes)
27+
return Application(routes, debug=True)
2828

2929

3030
wsgi_app = create_app()

0 commit comments

Comments
 (0)