Open anarcat opened 9 years ago
i am not sure, but this certainly looks like a degenerate case of the completion code in bookie.models.TagMgr.complete(). i wonder if we shouldn't put a minimum on the size of completion requests. for example, it looks like in the above query, it looks at all bookmarks that match o
or debian
. I believe this happened because i typed o rganisation
and bookie parsed that as two tags, then submitted that to the completion engine trying to complete rganisation
.
there are multiple ways of doing this. one is in the UI:
--- a/bookie/static/js/bookie/tagcontrol.js
+++ b/bookie/static/js/bookie/tagcontrol.js
@@ -417,6 +417,10 @@ YUI.add('bookie-tagcontrol', function (Y) {
*/
_fetch_suggestions: function (qry, callback) {
var tags;
+ // don't autcomplete short terms which may overload the database
+ if (qry.length <= 3) {
+ return '';
+ }
this.ac.api = new Y.bookie.Api.route.TagComplete(
this.get('api_cfg')
);
... but i don't think that's the right approach, personnally, because a malicious API user could still blow up the database. besides, the above patch only limits the size of rganisation
and not o
in the above example.
an alternative would be in the API itself:
diff --git a/bookie/views/api.py b/bookie/views/api.py
index 17c1172..54aebf7 100644
--- a/bookie/views/api.py
+++ b/bookie/views/api.py
@@ -624,11 +624,11 @@ def tag_complete(request):
return _api_response(request, {})
if 'current' in params and params['current'] != "":
- current_tags = params['current'].split()
+ current_tags = [ x for x in params['current'].split() if len(x) > 3 ]
else:
current_tags = None
- if 'tag' in params and params['tag']:
+ if 'tag' in params and params['tag'] and len(params['tag']) > 3:
tag = params['tag']
tags = TagMgr.complete(tag,
I would suggest working on the latter, the number 3
being arbitrary. It should obviously be a config variable of some sort, but before digging any deeper, i'd like to hear some feedback.
We'll try using the latter in production now.
we sometimes see the mysql server freak out because of bookie mysql users:
The MySQL server would completely hog a CPU per such query, during a few minutes.
The complete query is:
EXPLAIN doesn't outline anything very obvious, other than filesort issues, which maybe means we need to ramp up the sort_buffer variable...
I was wondering if this query shouldn't be optimised in some way... That sure looks like a lot of subqueries...