Skip to content

Commit

Permalink
Fix issues with sync'ing being slow or timing out learningequality#5614
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Bach committed Nov 8, 2019
1 parent 2c64bb3 commit b921e6b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion kalite/packages/bundled/fle_utils/internet/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def api_handle_error_with_json_wrapper_fn(request, *args, **kwargs):
except Http404:
raise
except Exception as e:
logger.error("Error in JSON view: {}".format(request.path))
if hasattr(request, 'path'):
logger.error("Error in JSON view: {}".format(request.path))
else:
logger.error("Error in JSON view. Request also has no attribute 'path', so not sure how this got called.")
logger.error(request)
traceback.print_exc()
return JsonResponseMessageError(_("Unexpected error: %(err)s") % {"err": e}, status=500)
return api_handle_error_with_json_wrapper_fn
Expand Down
3 changes: 2 additions & 1 deletion kalite/packages/bundled/securesync/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def __init__(self, host=None, require_trusted=True, verbose=True):
self.url = settings.CENTRAL_SERVER_URL
else:
self.url = "%s://%s/" % (settings.SECURESYNC_PROTOCOL, settings.CENTRAL_SERVER_HOST)
self.parsed_url = urllib2.urlparse.urlparse(self.url)
else:
parsed_url = urllib2.urlparse.urlparse(host)
self.parsed_url = urllib2.urlparse.urlparse(host)
self.url = "%s://%s" % (self.parsed_url.scheme, self.parsed_url.netloc)

self.require_trusted = require_trusted
Expand Down
8 changes: 7 additions & 1 deletion kalite/packages/bundled/securesync/engine/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ class SyncClient(BaseClient):
session = None

def post(self, path, payload={}, *args, **kwargs):
kwargs.setdefault("timeout", 120)
if self.session and self.session.client_nonce:
payload["client_nonce"] = self.session.client_nonce
return super(SyncClient, self).post(path, payload, *args, **kwargs)

def get(self, path, payload={}, *args, **kwargs):
# Set a high timeout since the server can be heavily loaded at times
kwargs.setdefault("timeout", 120)
if self.session and self.session.client_nonce:
payload["client_nonce"] = self.session.client_nonce
# add a random parameter to ensure the request is not cached
Expand Down Expand Up @@ -145,7 +148,10 @@ def close_session(self):

def get_server_device_counters(self):
r = self.get("device/counters")
data = json.loads(r.content or "{}")
try:
data = json.loads(r.content or "{}")
except ValueError:
raise Exception("Did not receive proper JSON data from server. URL: {}\n\nActual data:\n\n{}".format(r.url, r.content))
if "error" in data:
raise Exception("Server error in retrieving counters: " + data["error"])
return data.get("device_counters", {})
Expand Down
2 changes: 1 addition & 1 deletion kalite/packages/bundled/securesync/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_device_counters(**kwargs):

# The local device may have items that haven't incremented the device counter,
# but instead have deferred until sync time. Include those!
if device.is_own_device():
if not getattr(settings, 'CENTRAL_SERVER', False) and device.is_own_device():
cnt = 0
for Model in _syncing_models:
cnt += Model.all_objects.filter(Q(counter__isnull=True) | Q(signature__isnull=True)).count() # include deleted records
Expand Down

0 comments on commit b921e6b

Please sign in to comment.