diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-09-11 16:42:37 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-09-11 16:42:37 +0300 |
commit | 8f1e207120b9c596488c28ba7c1f43cddce29c86 (patch) | |
tree | b7d340f3199f04581c5b8616fe7eee130c274a18 /app/src/main/java/it/niedermann/nextcloud/deck/persistence | |
parent | dd8007a27ed62d3a9c2135e785d4cb0e96ed597e (diff) |
#608 WIP, duplicate labels fixed, now we get some wrong users assigned...
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/persistence')
7 files changed, 65 insertions, 17 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java index c659bb548..1833e1e2a 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java @@ -710,6 +710,11 @@ public class DataBaseAdapter { return db.getAttachmentDao().getLocallyChangedAttachmentsDirectly(accountId); } + @WorkerThread + public List<Attachment> getLocallyChangedAttachmentsForStackDirectly(long localStackId) { + return db.getAttachmentDao().getLocallyChangedAttachmentsForStackDirectly(localStackId); + } + public long createAttachment(long accountId, @NonNull Attachment attachment) { attachment.setAccountId(accountId); attachment.setCreatedAt(new Date()); @@ -812,11 +817,15 @@ public class DataBaseAdapter { return db.getJoinCardWithLabelDao().getAllDeletedJoinsWithRemoteIDs(); } - public List<JoinCardWithLabel> getAllChangedJoins() { + public List<JoinCardWithLabel> getAllChangedLabelJoins() { return db.getJoinCardWithLabelDao().getAllChangedJoins(); } - public JoinCardWithLabel getRemoteIdsForJoin(Long localCardId, Long localLabelId) { + public List<JoinCardWithLabel> getAllChangedLabelJoinsForStack(Long localStackId) { + return db.getJoinCardWithLabelDao().getAllChangedJoinsForStack(localStackId); + } + + public JoinCardWithLabel getAllChangedLabelJoinsWithRemoteIDs(Long localCardId, Long localLabelId) { return db.getJoinCardWithLabelDao().getRemoteIdsForJoin(localCardId, localLabelId); } @@ -824,6 +833,10 @@ public class DataBaseAdapter { return db.getJoinCardWithUserDao().getChangedJoinsWithRemoteIDs(); } + public List<JoinCardWithUser> getAllChangedUserJoinsWithRemoteIDsForStack(Long localStackId) { + return db.getJoinCardWithUserDao().getChangedJoinsWithRemoteIDsForStack(localStackId); + } + public void deleteJoinedLabelForCardPhysicallyByRemoteIDs(Long accountId, Long remoteCardId, Long remoteLabelId) { db.getJoinCardWithLabelDao().deleteJoinedLabelForCardPhysicallyByRemoteIDs(accountId, remoteCardId, remoteLabelId); } @@ -929,11 +942,17 @@ public class DataBaseAdapter { return db.getCommentDao().getCommentByLocalCardIdDirectly(localCardId); } + @WorkerThread public List<Card> getCardsWithLocallyChangedCommentsDirectly(Long accountId) { return db.getCardDao().getCardsWithLocallyChangedCommentsDirectly(accountId); } @WorkerThread + public List<Card> getCardsWithLocallyChangedCommentsForStackDirectly(Long localStackId) { + return db.getCardDao().getCardsWithLocallyChangedCommentsForStackDirectly(localStackId); + } + + @WorkerThread public Long getLocalStackIdByRemoteStackIdDirectly(long accountId, Long stackId) { return db.getStackDao().getLocalStackIdByRemoteStackIdDirectly(accountId, stackId); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/AttachmentDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/AttachmentDao.java index 2d0887903..8f7ee1cba 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/AttachmentDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/AttachmentDao.java @@ -25,6 +25,10 @@ public interface AttachmentDao extends GenericDao<Attachment> { @Query("SELECT * FROM attachment WHERE accountId = :accountId and (status<>1 or id is null or lastModified <> lastModifiedLocal)") List<Attachment> getLocallyChangedAttachmentsDirectly(long accountId); + @Query("SELECT a.* FROM attachment a inner join card c on c.localId = a.cardId " + + "WHERE c.stackId = :localStackId and (a.status<>1 or a.id is null or a.lastModified <> a.lastModifiedLocal)") + List<Attachment> getLocallyChangedAttachmentsForStackDirectly(long localStackId); + @Query("SELECT * FROM attachment WHERE accountId = :accountId and cardId = :localCardId") List<Attachment> getAttachmentsForLocalCardIdDirectly(long accountId, Long localCardId); }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java index 03c910ffc..d77a3b6b4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java @@ -70,6 +70,9 @@ public interface CardDao extends GenericDao<Card> { @Query("SELECT * FROM card c WHERE accountId = :accountId and exists ( select 1 from DeckComment dc where dc.objectId = c.localId and dc.status<>1)") List<Card> getCardsWithLocallyChangedCommentsDirectly(Long accountId); + @Query("SELECT * FROM card c WHERE stackId = :localStackId and exists ( select 1 from DeckComment dc where dc.objectId = c.localId and dc.status<>1)") + List<Card> getCardsWithLocallyChangedCommentsForStackDirectly(Long localStackId); + @Query("SELECT count(*) FROM card c WHERE accountId = :accountId and stackId = :localStackId and status <> 3") LiveData<Integer> countCardsInStack(long accountId, long localStackId); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithLabelDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithLabelDao.java index c96c64e7d..26e6c65a8 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithLabelDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithLabelDao.java @@ -40,6 +40,9 @@ public interface JoinCardWithLabelDao extends GenericDao<JoinCardWithLabel> { @Query("select * from joincardwithlabel WHERE status <> 1") // not UP_TO_DATE List<JoinCardWithLabel> getAllChangedJoins(); + @Query("select j.* from joincardwithlabel j inner join card c on j.cardId = c.localId WHERE c.stackId = :localStackId and j.status <> 1") // not UP_TO_DATE + List<JoinCardWithLabel> getAllChangedJoinsForStack(Long localStackId); + @Query("delete from joincardwithlabel " + "where cardId = (select c.localId from card c where c.accountId = :accountId and c.id = :remoteCardId) " + "and labelId = (select l.localId from label l where l.accountId = :accountId and l.id = :remoteLabelId)") diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java index 9d8e2cf9d..416d52eed 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java @@ -27,6 +27,13 @@ public interface JoinCardWithUserDao extends GenericDao<JoinCardWithUser> { "WHERE j.status <> 1") // not UP_TO_DATE List<JoinCardWithUser> getChangedJoinsWithRemoteIDs(); + @Query("select u.localId as userId, c.id as cardId, j.status from joincardwithuser j " + + "inner join card c on j.cardId = c.localId " + + "inner join user u on j.userId = u.localId " + + "WHERE c.stackId = :localStackId " + + "AND j.status <> 1") // not UP_TO_DATE + List<JoinCardWithUser> getChangedJoinsWithRemoteIDsForStack(Long localStackId); + @Query("delete from joincardwithuser " + "where cardId = (select c.localId from card c where c.accountId = :accountId and c.id = :remoteCardId) " + "and userId = (select u.localId from user u where u.accountId = :accountId and u.uid = :userUid)") diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java index 4c7cc4b57..00c2f8bd6 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java @@ -187,8 +187,13 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { public void goDeeperForUpSync(SyncHelper syncHelper, ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, IResponseCallback<Boolean> callback) { FullStack stack; Board board; + List<JoinCardWithLabel> changedLabels; + if (this.stack == null) { + changedLabels = dataBaseAdapter.getAllChangedLabelJoins(); + } else { + changedLabels = dataBaseAdapter.getAllChangedLabelJoinsForStack(this.stack.getLocalId()); + } - List<JoinCardWithLabel> changedLabels = dataBaseAdapter.getAllChangedJoins(); Account account = callback.getAccount(); for (JoinCardWithLabel changedLabelLocal : changedLabels) { Card card = dataBaseAdapter.getCardByLocalIdDirectly(account.getId(), changedLabelLocal.getCardId()); @@ -204,7 +209,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { board = this.board; } - JoinCardWithLabel changedLabel = dataBaseAdapter.getRemoteIdsForJoin(changedLabelLocal.getCardId(), changedLabelLocal.getLabelId()); + JoinCardWithLabel changedLabel = dataBaseAdapter.getAllChangedLabelJoinsWithRemoteIDs(changedLabelLocal.getCardId(), changedLabelLocal.getLabelId()); if (changedLabel.getStatusEnum() == DBStatus.LOCAL_DELETED) { if (changedLabel.getLabelId() == null || changedLabel.getCardId() == null) { dataBaseAdapter.deleteJoinedLabelForCardPhysicallyByRemoteIDs(account.getId(), changedLabel.getCardId(), changedLabel.getLabelId()); @@ -232,7 +237,13 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { } } - List<JoinCardWithUser> changedUsers = dataBaseAdapter.getAllChangedUserJoinsWithRemoteIDs(); + + List<JoinCardWithUser> changedUsers; + if (this.stack == null) { + changedUsers = dataBaseAdapter.getAllChangedUserJoinsWithRemoteIDs(); + } else { + changedUsers = dataBaseAdapter.getAllChangedUserJoinsWithRemoteIDsForStack(this.stack.getLocalId()); + } for (JoinCardWithUser changedUser : changedUsers) { // not already known to server? if (changedUser.getCardId() == null) { @@ -269,7 +280,12 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { } } - List<Attachment> attachments = dataBaseAdapter.getLocallyChangedAttachmentsDirectly(account.getId()); + List<Attachment> attachments; + if (this.stack == null) { + attachments = dataBaseAdapter.getLocallyChangedAttachmentsDirectly(account.getId()); + } else { + attachments = dataBaseAdapter.getLocallyChangedAttachmentsForStackDirectly(this.stack.getLocalId()); + } for (Attachment attachment : attachments) { FullCard card = dataBaseAdapter.getFullCardByLocalIdDirectly(account.getId(), attachment.getCardId()); stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getCard().getStackId()); @@ -277,7 +293,12 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { syncHelper.doUpSyncFor(new AttachmentDataProvider(this, board, stack.getStack(), card, Collections.singletonList(attachment))); } - List<Card> cardsWithChangedComments = dataBaseAdapter.getCardsWithLocallyChangedCommentsDirectly(account.getId()); + List<Card> cardsWithChangedComments; + if (this.stack == null) { + cardsWithChangedComments = dataBaseAdapter.getCardsWithLocallyChangedCommentsDirectly(account.getId()); + } else { + cardsWithChangedComments = dataBaseAdapter.getCardsWithLocallyChangedCommentsForStackDirectly(this.stack.getLocalId()); + } for (Card card : cardsWithChangedComments) { syncHelper.doUpSyncFor(new DeckCommentsDataProvider(this, card)); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/StackDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/StackDataProvider.java index 41f1111ed..ba305dc0a 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/StackDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/StackDataProvider.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentSkipListSet; -import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.api.IResponseCallback; import it.niedermann.nextcloud.deck.model.Board; import it.niedermann.nextcloud.deck.model.Card; @@ -20,14 +19,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.helpers.SyncHelper; public class StackDataProvider extends AbstractSyncDataProvider<FullStack> { private FullBoard board; - private Set<Long> syncedStacks = new ConcurrentSkipListSet<Long>(){ - @Override - public boolean add(Long o) { - boolean add = super.add(o); - DeckLog.error("SyncedStacks for "+o+" added: "+add); - return add; - } - }; + private Set<Long> syncedStacks = new ConcurrentSkipListSet<>(); public StackDataProvider(AbstractSyncDataProvider<?> parent, FullBoard board) { super(parent); @@ -124,7 +116,6 @@ public class StackDataProvider extends AbstractSyncDataProvider<FullStack> { syncedStacks.add(stackId); Board board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId()); changedCard.getCard().setStackId(stack.getId()); - DeckLog.error("syncing stack with localID "+stack.getLocalId()); syncHelper.doUpSyncFor(new CardDataProvider(this, board, stack)); } } |