Permalink
Browse files

if SQLite is built with the optional json1 extension, use a straight …

…SELECT instead of a temp table for the view, thus reducing timeouts when /view is locked out by hourly feed updates
  • Loading branch information...
Fazal Majid
Fazal Majid committed Oct 15, 2018
1 parent 155e151 commit 1bb9e8c36d244a3b189f6faca04ecc0773a0f374
Showing with 46 additions and 3 deletions.
  1. +43 −2 tembozapp/dbop.py
  2. +1 −1 tembozapp/server.py
  3. +2 −0 tembozapp/templates/settings.html
@@ -1,4 +1,4 @@
import sys, time, sqlite3, string
import sys, time, sqlite3, string, json
import param
def db():
@@ -178,8 +178,22 @@ def elapsed(t, what):
t2 = time.time()
print >> param.log, what, (t2-t)* 1000, 'ms'
return t2
use_json = None
def view_sql(c, where, sort, params, overload_threshold):
global use_json
if use_json is None:
try:
c.execute("""select json_group_array(feed_uid) from fm_feeds""")
use_json = True
except:
use_json = False
if use_json:
return view_sql_json(c, where, sort, params, overload_threshold)
else:
view_sql_no_json(c, where, sort, params, overload_threshold)
def view_sql_no_json(c, where, sort, params, overload_threshold):
t = time.time()
mv_on_demand(c)
#t = elapsed(t, 'mv_on_demand')
@@ -211,6 +225,33 @@ def view_sql(c, where, sort, params, overload_threshold):
#t = elapsed(t, 'output')
return tag_dict, output
def view_sql_json(c, where, sort, params, overload_threshold):
mv_on_demand(c)
rows = c.execute("""select
item_uid, item_creator, item_title, item_link, item_content,
datetime(item_loaded), date(item_created) as item_created,
datetime(item_rated) as item_rated,
julianday('now') - julianday(item_created) as delta_created, item_rating,
item_rule_uid, item_feed_uid, feed_title, feed_html, feed_xml,
ifnull(snr, 0) as snr, updated,
json_group_array(tag_name)
from fm_items
join fm_feeds on item_feed_uid=feed_uid
left outer join mv_feed_stats on feed_uid=snr_feed_uid
left outer join fm_tags on tag_item_uid=item_uid
where item_feed_uid=feed_uid and """ + where + """
group by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
order by """ + sort + """, item_uid DESC limit ?""",
params + [overload_threshold])
tag_dict = dict()
output = []
for cols in rows:
cols = list(cols)
output.append(cols[:-1])
tags = json.loads(cols[-1])
tag_dict[cols[0]] = tags
return tag_dict, output
def feed_info_sql(c, feed_uid):
mv_on_demand(c)
return c.execute("""select feed_title, feed_desc, feed_filter,
@@ -693,7 +693,7 @@ def facebook():
+ '/facebook?op=oauth_redirect'
op = flask.request.args.get('op', '')
if not op:
fb_url = 'https://graph.facebook.com/oauth/authorize?display=touch&client_id=' + app_id + '&scope=publish_actions&redirect_uri=' + redir
fb_url = 'https://graph.facebook.com/oauth/authorize?display=touch&client_id=' + app_id + '&scope=publish_pages,manage_pages&redirect_uri=' + redir
print >> param.log, 'FB_URL =', fb_url
return flask.redirect(fb_url)
elif op == 'oauth_redirect':
@@ -221,6 +221,8 @@ <h2>Top filters</h2>
href="http://developers.facebook.com/">developer program</a></li>
<li>Register Temboz as an app</li>
<li>Obtain an App ID and API Key, and list them below</li>
<li>Request an App Review by Facebook for the <tt>publish_pages</tt> and
<tt>manage_pages</tt> permissions
<li><a href="facebook">Authorize</a> Temboz using OAUTH 2.0 to post on
your behalf</li>
</ol>

0 comments on commit 1bb9e8c

Please sign in to comment.