Skip to content

Commit

Permalink
fix: Enforce Stack queries when doing backup
Browse files Browse the repository at this point in the history
When doing a backup, we don't want instable network to make the
CozyClient use local PouchLink for some queries that need to read files
paths

In cozy/cozy-client#1575 we implemented the `forceStack` option that
allows to enforce the usage of StackLink instead of other links that
may retrieve local incomplete data

This commit enforce the stack on backup related queries

Related PR: cozy/cozy-client#1575
  • Loading branch information
Ldoppea committed Dec 20, 2024
1 parent cebf31b commit 3a4ad93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/app/domain/backup/services/manageLocalBackupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,15 @@ export const fixLocalBackupConfigIfNecessary = async (
const fileQuery = buildFileQuery(
localBackupConfig.remoteBackupConfig.backupFolder.id
)
const fileQueryOptions = { forceStack: true }

let remoteBackupFolderUpdated

try {
const { data } = (await client.query(fileQuery)) as FileCollectionGetResult
const { data } = (await client.query(
fileQuery,
fileQueryOptions
)) as FileCollectionGetResult

remoteBackupFolderUpdated = data
} catch (e) {
Expand Down
16 changes: 13 additions & 3 deletions src/app/domain/backup/services/manageRemoteBackupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ export const createRemoteBackupFolder = async (
)

const fileQuery = buildFileQuery(backupFolderId)
const fileQueryOptions = { forceStack: true }

const { data: backupFolder } = (await client.query(
fileQuery
fileQuery,
fileQueryOptions
)) as FileCollectionGetResult

const remoteBackupConfig = {
Expand Down Expand Up @@ -331,8 +333,12 @@ export const getRemoteFiles = (): File[] => {

const fetchAllRemoteFiles = async (client: CozyClient): Promise<File[]> => {
const filesQuery = buildAllMediasFilesQuery()
const fileQueryOptions = { forceStack: true }

const remoteFiles = (await client.queryAll(filesQuery)) as FilesQueryAllResult
const remoteFiles = (await client.queryAll(
filesQuery,
fileQueryOptions
)) as FilesQueryAllResult

const remoteFilesNotInTrash = remoteFiles.filter(
file => !isInTrash(file.path)
Expand Down Expand Up @@ -372,7 +378,11 @@ export const fetchBackupedMedias = async (

const filesQuery = buildFilesQuery(deviceId)

const data = (await client.queryAll(filesQuery)) as FilesQueryAllResult
const filesQueryOption = { forceStack: true }
const data = (await client.queryAll(
filesQuery,
filesQueryOption
)) as FilesQueryAllResult

const backupedMedias = filterMediasAlreadyBackuped(allMedias, data)

Expand Down

0 comments on commit 3a4ad93

Please sign in to comment.