1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-06 03:50:19 +02:00

sync optimisation & cleanup

This commit is contained in:
Nikolay Pultsin 2014-12-11 17:39:37 +00:00
parent 2d97483f42
commit 2bf79857cb
5 changed files with 21 additions and 9 deletions

View file

@ -8,6 +8,7 @@
* (planned) CSS selectors priority
===== 2.2 beta 8 (Dec ??, 2014) =====
* Sync optimisation: do not send unnecessary requests
* Fixed crash on old (2.0 and 2.1) devices
* Fixed opening of huge ePubs (300+ htmls inside)
* Fixed Smashwords catalog parsing

View file

@ -48,7 +48,7 @@ class SyncNetworkContext extends ServiceNetworkContext {
@Override
protected void perform(ZLNetworkRequest request, int socketTimeout, int connectionTimeout) throws ZLNetworkException {
if (!canPerformRequest()) {
throw new SyncronizationDisabledException();
throw new SynchronizationDisabledException();
}
final String accountName = SyncUtil.getAccountName(this);
if (!MiscUtil.equals(myAccountName, accountName)) {

View file

@ -48,8 +48,9 @@ public class SyncService extends Service implements IBookCollection.Listener {
Uploaded(Book.SYNCHRONISED_LABEL),
ToBeDeleted(Book.SYNC_DELETED_LABEL),
Failure(Book.SYNC_FAILURE_LABEL),
AuthenticationError(null),
ServerError(null),
SyncronizationDisabled(null),
SynchronizationDisabled(null),
FailedPreviuousTime(null),
HashNotComputed(null);
@ -141,7 +142,7 @@ public class SyncService extends Service implements IBookCollection.Listener {
alarmManager.setInexactRepeating(
AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime(),
AlarmManager.INTERVAL_HALF_HOUR,
AlarmManager.INTERVAL_HOUR,
syncIntent()
);
SQLiteCookieDatabase.init(SyncService.this);
@ -203,7 +204,7 @@ public class SyncService extends Service implements IBookCollection.Listener {
});
log("RECEIVED: " + myHashesFromServer.toString());
}
} catch (SyncronizationDisabledException e) {
} catch (SynchronizationDisabledException e) {
myHashesFromServer.clear();
throw e;
} catch (Exception e) {
@ -239,10 +240,11 @@ public class SyncService extends Service implements IBookCollection.Listener {
addBook(b);
}
}
while (!myQueue.isEmpty()) {
Status status = null;
while (!myQueue.isEmpty() && status != Status.AuthenticationError) {
final Book book = myQueue.remove(0);
++count;
final Status status = uploadBookToServer(book);
status = uploadBookToServer(book);
if (status.Label != null) {
for (String label : Status.AllLabels) {
if (status.Label.equals(label)) {
@ -361,8 +363,8 @@ public class SyncService extends Service implements IBookCollection.Listener {
private Status uploadBookToServer(Book book) {
try {
return uploadBookToServerInternal(book);
} catch (SyncronizationDisabledException e) {
return Status.SyncronizationDisabled;
} catch (SynchronizationDisabledException e) {
return Status.SynchronizationDisabled;
}
}
@ -395,6 +397,9 @@ public class SyncService extends Service implements IBookCollection.Listener {
};
try {
myBookUploadContext.perform(verificationRequest);
} catch (ZLNetworkAuthenticationException e) {
e.printStackTrace();
return Status.AuthenticationError;
} catch (ZLNetworkException e) {
e.printStackTrace();
return Status.ServerError;
@ -409,6 +414,9 @@ public class SyncService extends Service implements IBookCollection.Listener {
uploadRequest.addHeader("X-CSRFToken", csrfToken);
myBookUploadContext.perform(uploadRequest);
return uploadRequest.Result;
} catch (ZLNetworkAuthenticationException e) {
e.printStackTrace();
return Status.AuthenticationError;
} catch (ZLNetworkException e) {
e.printStackTrace();
return Status.ServerError;

View file

@ -19,5 +19,5 @@
package org.geometerplus.android.fbreader.sync;
class SyncronizationDisabledException extends RuntimeException {
class SynchronizationDisabledException extends RuntimeException {
}

View file

@ -171,6 +171,9 @@ public class SyncData {
currentBookMap.put("timestamp", Long.parseLong(myCurrentBookTimestamp.getValue()));
} catch (Exception e) {
}
if (currentBook.File.getPhysicalFile() == null) {
currentBookMap.put("default", 0);
}
map.put("currentbook", currentBookMap);
final List<Map<String,Object>> lst = new ArrayList<Map<String,Object>>();