Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
fb20ea9
Simplify electron autoupdater
dajimenezriv-internxt Apr 23, 2026
00d2e0a
Commit
dajimenezriv-internxt Apr 24, 2026
480af77
Commit
dajimenezriv-internxt Apr 24, 2026
40392dd
Commit
dajimenezriv-internxt Apr 24, 2026
25e43e4
Commit
dajimenezriv-internxt Apr 24, 2026
7e129c2
Update download-release.ts
dajimenezriv-internxt Apr 24, 2026
818afd7
Commit
dajimenezriv-internxt Apr 24, 2026
23b0e49
Commit
dajimenezriv-internxt Apr 24, 2026
bffe603
Commit
dajimenezriv-internxt Apr 24, 2026
39dd64e
Commit
dajimenezriv-internxt Apr 24, 2026
6b6f372
Commit
dajimenezriv-internxt Apr 24, 2026
0730c92
Commit
dajimenezriv-internxt Apr 27, 2026
9319504
Update verify-hash.ts
dajimenezriv-internxt Apr 27, 2026
e846494
Update verify-hash.test.ts
dajimenezriv-internxt Apr 27, 2026
5c96446
Commit
dajimenezriv-internxt Apr 27, 2026
efc351e
Update check-for-updates.test.ts
dajimenezriv-internxt Apr 27, 2026
300dda3
Commit
dajimenezriv-internxt Apr 27, 2026
7158c99
Update check-and-install.test.ts
dajimenezriv-internxt Apr 27, 2026
28a145b
Update check-for-updates.test.ts
dajimenezriv-internxt Apr 27, 2026
3c8e632
Update access.test.ts
dajimenezriv-internxt Apr 27, 2026
a9133a9
Update show-dialog.ts
dajimenezriv-internxt Apr 27, 2026
09e2887
Update access.test.ts
dajimenezriv-internxt Apr 28, 2026
50f52ff
Revert "Update access.test.ts"
dajimenezriv-internxt Apr 28, 2026
86fb6a0
Reapply "Update access.test.ts"
dajimenezriv-internxt Apr 28, 2026
6566001
Revert "Reapply "Update access.test.ts""
dajimenezriv-internxt Apr 28, 2026
3d6f931
Reapply "Reapply "Update access.test.ts""
dajimenezriv-internxt Apr 28, 2026
892da7b
Update access.test.ts
dajimenezriv-internxt Apr 28, 2026
50fb229
Create get_open_file_explorers.h
dajimenezriv-internxt Apr 29, 2026
0f0cf67
Commit
dajimenezriv-internxt Apr 30, 2026
c5dbe17
Update verify-hash.test.ts
dajimenezriv-internxt Apr 30, 2026
ac00d9a
Move folder instead of delete
dajimenezriv-internxt Apr 30, 2026
be6a7da
Merge branch 'move-folder-instead-of-delete' into improve-app-perform…
dajimenezriv-internxt Apr 30, 2026
df2994e
Update watcher-on-unlink.test.ts
dajimenezriv-internxt Apr 30, 2026
5534ae7
Organize C++ code
dajimenezriv-internxt Apr 30, 2026
6f07b12
Migrate openFileHandle
dajimenezriv-internxt Apr 30, 2026
b9e83f1
Migrate updateSyncStatus
dajimenezriv-internxt Apr 30, 2026
2dea89f
Migrate dehydrateFile
dajimenezriv-internxt Apr 30, 2026
6fc3311
Migrate createFilePlaceholder
dajimenezriv-internxt Apr 30, 2026
1e4c7c9
Migrate createFolderPlaceholder
dajimenezriv-internxt Apr 30, 2026
bf82159
Migrate disconnectSyncRoot
dajimenezriv-internxt Apr 30, 2026
3891bd5
Migrate hydrateFile
dajimenezriv-internxt Apr 30, 2026
24ca9ee
Migrate registerSyncRoot
dajimenezriv-internxt Apr 30, 2026
c0a954c
Migrate setPinState
dajimenezriv-internxt Apr 30, 2026
7380940
Migrate unregisterSyncRoot
dajimenezriv-internxt Apr 30, 2026
8285c0b
Migrate getRegisteredSyncRoots
dajimenezriv-internxt Apr 30, 2026
c99221f
Commit
dajimenezriv-internxt Apr 30, 2026
4c5ba09
Commit
dajimenezriv-internxt Apr 30, 2026
eb4fb6e
Revert "Migrate getRegisteredSyncRoots"
dajimenezriv-internxt Apr 30, 2026
f8e66e4
Organize C++ code
dajimenezriv-internxt Apr 30, 2026
6802a92
Update check-pr-size.yml
dajimenezriv-internxt Apr 30, 2026
b25fed9
Update virtual_drive.h
dajimenezriv-internxt Apr 30, 2026
8ebf039
Merge branch 'organize-c++-code' into orgnaize-c++-code-2
dajimenezriv-internxt Apr 30, 2026
f57e111
Migrate getPlaceholderState
dajimenezriv-internxt Apr 30, 2026
0617c6b
Commit
dajimenezriv-internxt Apr 30, 2026
6e2e14a
Merge branch 'orgnaize-c++-code-2' into move-folder-instead-of-delete
dajimenezriv-internxt Apr 30, 2026
322ac6d
Organize C++ code (3)
dajimenezriv-internxt Apr 30, 2026
94a5385
Commit
dajimenezriv-internxt Apr 30, 2026
d433684
Update addon-sonar-analysis.yml
dajimenezriv-internxt Apr 30, 2026
34de9c9
Merge branch 'organize-c++-code-3' into move-folder-instead-of-delete
dajimenezriv-internxt Apr 30, 2026
3b13fa3
Commit
dajimenezriv-internxt Apr 30, 2026
9a995c0
Commit
dajimenezriv-internxt Apr 30, 2026
b46532d
Commit
dajimenezriv-internxt Apr 30, 2026
90f2b60
Commit
dajimenezriv-internxt Apr 30, 2026
872d2f2
Merge branch 'move-folder-instead-of-delete' into improve-app-perform…
dajimenezriv-internxt Apr 30, 2026
fd58590
Commit
dajimenezriv-internxt May 1, 2026
d296c0b
Commit
dajimenezriv-internxt May 4, 2026
747db21
Commit
dajimenezriv-internxt May 4, 2026
4fc473c
Commit
dajimenezriv-internxt May 4, 2026
b28fa4f
Commit
dajimenezriv-internxt May 4, 2026
0f629ba
Commit
dajimenezriv-internxt May 4, 2026
fa19050
Merge branch 'main' into organize-c++-code
dajimenezriv-internxt May 4, 2026
1e1c71c
Update check-pr-size.yml
dajimenezriv-internxt May 4, 2026
21aac93
Merge branch 'organize-c++-code' into orgnaize-c++-code-2
dajimenezriv-internxt May 5, 2026
7e0c303
Merge branch 'main' into orgnaize-c++-code-2
dajimenezriv-internxt May 5, 2026
1e3f420
Merge branch 'main' into orgnaize-c++-code-2
dajimenezriv-internxt May 5, 2026
16d2826
Merge branch 'orgnaize-c++-code-2' into organize-c++-code-3
dajimenezriv-internxt May 5, 2026
0acf428
Merge branch 'main' into organize-c++-code-3
dajimenezriv-internxt May 6, 2026
93f8ef5
Merge branch 'organize-c++-code-3' into move-folder-instead-of-delete
dajimenezriv-internxt May 6, 2026
ff6aed7
Merge branch 'main' into move-folder-instead-of-delete
dajimenezriv-internxt May 6, 2026
5cb369f
Merge branch 'main' into move-folder-instead-of-delete
dajimenezriv-internxt May 6, 2026
cb19c07
Merge branch 'move-folder-instead-of-delete' into improve-app-perform…
dajimenezriv-internxt May 6, 2026
1053015
Add sqlite getByParentUuid (#1369)
dajimenezriv-internxt May 7, 2026
4d55378
Commit
dajimenezriv-internxt May 7, 2026
52b1870
Merge branch 'main' into move-folder-instead-of-delete
dajimenezriv-internxt May 7, 2026
9229a90
Merge branch 'move-folder-instead-of-delete' into improve-app-perform…
dajimenezriv-internxt May 7, 2026
5bcf8fd
Commit
dajimenezriv-internxt May 7, 2026
dfd3b33
Revert "Commit"
dajimenezriv-internxt May 7, 2026
ee6c2ca
Merge branch 'main' into improve-app-performance
dajimenezriv-internxt May 9, 2026
959a041
Commit
dajimenezriv-internxt May 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion knip.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"entry": ["src/apps/main/main.ts", "src/apps/renderer/index.tsx"],
"exclude": ["devDependencies"],
"ignore": ["**/*.test.{ts,tsx}", "src/apps/shared/HttpClient/schema.ts", "src/migrations/v2.5.6/move-checkpoint-to-lokijs.ts"],
"ignore": ["**/*.test.{ts,tsx}", "src/apps/shared/HttpClient/schema.ts"],
"ignoreBinaries": ["powershell", "esbuild", "node-gyp", "sqlite3"],
"ignoreExportsUsedInFile": true,
"project": ["src/**/*.{ts,tsx}"],
Expand Down
422 changes: 54 additions & 368 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
"regenerator-runtime": "^0.13.9",
"socket.io-client": "^4.8.3",
"source-map-support": "^0.5.21",
"trash": "^10.1.1",
"zustand": "^4.5.7"
},
"engines": {
Expand Down
Binary file modified packages/addon/dist/addon.node
Binary file not shown.
3 changes: 3 additions & 0 deletions packages/addon/include/external.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include <ShlObj_core.h>
#include <Windows.h>
#include <atlbase.h>
#include <cfapi.h>
#include <exdispid.h>
#include <node_api.h>
#include <ntstatus.h>
#include <propkey.h>
Expand All @@ -16,6 +18,7 @@
#include <filesystem>
#include <functional>
#include <mutex>
#include <set>
#include <string>

namespace winrt
Expand Down
13 changes: 13 additions & 0 deletions packages/addon/include/helpers/napi_serializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ struct NapiSerializer<std::optional<std::wstring>> {
}
};

template <>
struct NapiSerializer<std::vector<std::wstring>> {
static napi_value serialize(napi_env env, const std::vector<std::wstring>& values)
{
napi_value result;
napi_create_array_with_length(env, values.size(), &result);
for (uint32_t i = 0; i < values.size(); i++) {
napi_set_element(env, result, i, NapiSerializer<std::wstring>::serialize(env, values[i]));
}
return result;
}
};

inline void napiSetString(napi_env env, napi_value obj, const char* key, const std::string& value)
{
napi_value val;
Expand Down
3 changes: 2 additions & 1 deletion packages/addon/include/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

#include <virtual_drive/open_file_handle.h>
#include <virtual_drive/register_fetch_data_callback.h>
#include <virtual_drive/watcher/watcher_defs.h>

#include <virtual_drive/connect_sync_root.h>
#include <virtual_drive/convert_to_placeholder.h>
#include <virtual_drive/create_file_placeholder.h>
#include <virtual_drive/create_folder_placeholder.h>
#include <virtual_drive/dehydrate_file.h>
#include <virtual_drive/disconnect_sync_root.h>
#include <virtual_drive/get_file_explorers.h>
#include <virtual_drive/get_first_non_placeholder.h>
#include <virtual_drive/get_placeholder_state.h>
#include <virtual_drive/get_registered_sync_roots.h>
Expand All @@ -34,6 +36,5 @@
#include <virtual_drive/unregister_sync_root.h>
#include <virtual_drive/update_placeholder.h>
#include <virtual_drive/update_sync_status.h>
#include <virtual_drive/watcher/watcher_defs.h>
#include <virtual_drive/watcher/unwatch_path.h>
#include <virtual_drive/watcher/watch_path.h>
72 changes: 72 additions & 0 deletions packages/addon/include/virtual_drive/get_file_explorers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#pragma once

inline std::wstring getPathFromDispatch(IDispatch* dispatch)
{
CComQIPtr<IWebBrowserApp> app(dispatch);
if (!app) winrt::check_hresult(E_NOINTERFACE);

CComQIPtr<IServiceProvider> sp(app);
if (!sp) winrt::check_hresult(E_NOINTERFACE);

CComPtr<IShellBrowser> sb;
winrt::check_hresult(sp->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, (void**)&sb));

CComPtr<IShellView> sv;
winrt::check_hresult(sb->QueryActiveShellView(&sv));

CComQIPtr<IFolderView> fv(sv);
if (!fv) winrt::check_hresult(E_NOINTERFACE);

CComPtr<IPersistFolder2> pf;
winrt::check_hresult(fv->GetFolder(IID_IPersistFolder2, (void**)&pf));

LPITEMIDLIST pidl = nullptr;
winrt::check_hresult(pf->GetCurFolder(&pidl));

wchar_t path[MAX_PATH] = {};
BOOL ok = SHGetPathFromIDListW(pidl, path);
CoTaskMemFree(pidl);
if (!ok) return {};

return path;
}

inline std::vector<std::wstring> getFileExplorers()
{
HRESULT coHr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
winrt::check_hresult(coHr);

CComPtr<IShellWindows> shellWindows;
winrt::check_hresult(CoCreateInstance(CLSID_ShellWindows, nullptr, CLSCTX_ALL, IID_IShellWindows, (void**)&shellWindows));

long count = 0;
shellWindows->get_Count(&count);

std::vector<std::wstring> paths;
for (long i = 0; i < count; i++) {
try {
CComVariant idx(i);
CComPtr<IDispatch> dispatch;
shellWindows->Item(idx, &dispatch);

std::wstring path = getPathFromDispatch(dispatch);
if (!path.empty()) {
paths.push_back(std::move(path));
}
} catch (...) {
}
}

CoUninitialize();
return paths;
}

inline napi_value getFileExplorersWrapper(napi_env env, napi_callback_info)
{
return run_async(env, "GetFileExplorers", getFileExplorers);
}

inline napi_value GetFileExplorersWrapper(napi_env env, napi_callback_info info)
{
return NAPI_SAFE_WRAP(env, info, getFileExplorersWrapper);
}
7 changes: 3 additions & 4 deletions packages/addon/include/virtual_drive/watcher/watch_path.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

inline void callJsCallback(napi_env env, napi_value jsCallback, void* context, void* data)
inline void callWatcherJsCallback(napi_env env, napi_value jsCallback, void* context, void* data)
{
WatcherEvent* event = static_cast<WatcherEvent*>(data);

Expand Down Expand Up @@ -125,7 +125,7 @@ inline napi_value watchPathWrapper(napi_env env, napi_callback_info info)
{
auto [rootPath, onEventCallback] = napi_extract_args<std::wstring, napi_value>(env, info);

auto tsfn = registerThreadsafeCallback("WatchPathCallback", env, onEventCallback, callJsCallback);
auto tsfn = registerThreadsafeCallback("WatchPathCallback", env, onEventCallback, callWatcherJsCallback);

auto ctx = new WatcherContext{tsfn, false};

Expand All @@ -142,8 +142,7 @@ inline napi_value watchPathWrapper(napi_env env, napi_callback_info info)
napi_release_threadsafe_function(ctx->tsfn, napi_tsfn_release);
delete ctx;
} catch (...) {
auto error = format_exception_message("WatchPathThread");
wprintf(L"Error in watch path thread: %s\n", error.c_str());
wprintf(L"%S\n", format_exception_message("WatchPathThread").c_str());
}
}).detach();

Expand Down
Binary file modified packages/addon/packages-addon-1.0.0.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions packages/addon/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ napi_value init(napi_env env, napi_value exports)
{"createFolderPlaceholder", nullptr, CreateFolderPlaceholderWrapper, nullptr, nullptr, nullptr, napi_default, nullptr},
{"dehydrateFile", nullptr, DehydrateFileWrapper, nullptr, nullptr, nullptr, napi_default, nullptr},
{"disconnectSyncRoot", nullptr, DisconnectSyncRootWrapper, nullptr, nullptr, nullptr, napi_default, nullptr},
{"getFileExplorers", nullptr, GetFileExplorersWrapper, nullptr, nullptr, nullptr, napi_default, nullptr},
{"getFirstNonPlaceholder", nullptr, getFirstNonPlaceholderWrapper, nullptr, nullptr, nullptr, napi_default, nullptr},
{"getPlaceholderState", nullptr, GetPlaceholderStateWrapper, nullptr, nullptr, nullptr, napi_default, nullptr},
{"getRegisteredSyncRoots", nullptr, GetRegisteredSyncRootsWrapper, nullptr, nullptr, nullptr, napi_default, nullptr},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { randomUUID } from 'node:crypto';
import { mkdir, rename, rm } from 'node:fs/promises';
import trash from 'trash';
import { FileUuid } from '@/apps/main/database/entities/DriveFile';
import { abs } from '@/context/local/localFile/infrastructure/AbsolutePath';
import { Addon } from '@/node-win/addon-wrapper';
import { loggerFn, loggerMock } from '@/tests/vitest/mocks.helper.test';
import { call, calls, deepMocked, partialSpyOn, TestProps } from '@/tests/vitest/utils.helper.test';
import { call, calls, partialSpyOn, TestProps } from '@/tests/vitest/utils.helper.test';
import { deleteItemPlaceholder } from './delete-item-placeholder';

vi.mock(import('node:fs/promises'));
vi.mock(import('node:crypto'));
vi.mock(import('trash'));

describe('delete-item-placeholder', () => {
const mkdirMock = deepMocked(mkdir);
const renameMock = deepMocked(rename);
const rmMock = deepMocked(rm);
const trashMock = deepMocked(trash);
const randomUUIDMock = deepMocked(randomUUID);
const mkdirMock = vi.mocked(mkdir);
const renameMock = vi.mocked(rename);
const rmMock = vi.mocked(rm);
const randomUUIDMock = vi.mocked(randomUUID);
const getFirstNonPlaceholderMock = partialSpyOn(Addon, 'getFirstNonPlaceholder');

const uuid = 'uuid' as FileUuid;
Expand Down Expand Up @@ -74,7 +71,7 @@ describe('delete-item-placeholder', () => {
{ msg: 'Delete placeholder' },
{ msg: 'Folder cannot be deleted because it contains a non placeholder item' },
]);
calls(trashMock).toHaveLength(0);
calls(rmMock).toHaveLength(0);
});

it('should delete folder if all folder items are placeholders', async () => {
Expand All @@ -86,6 +83,6 @@ describe('delete-item-placeholder', () => {
calls(loggerFn).toMatchObject([{ msg: 'Delete placeholder' }, { msg: 'Folder can be deleted, all items are placeholders' }]);
call(mkdirMock).toStrictEqual([trashDir, { recursive: true }]);
call(renameMock).toStrictEqual([localPath, trashPath]);
call(trashMock).toStrictEqual(trashPath);
call(rmMock).toStrictEqual([trashPath, { recursive: true, force: true }]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { join, parse } from 'node:path';
import { ExtendedDriveFile } from '@/apps/main/database/entities/DriveFile';
import { ExtendedDriveFolder } from '@/apps/main/database/entities/DriveFolder';
import { SyncContext } from '@/apps/sync-engine/config';
import { measurePerfomance } from '@/core/utils/measure-performance';
import { Addon } from '@/node-win/addon-wrapper';
import { FileExplorerFiles, FileExplorerFolders } from '../sync-items-by-checkpoint/load-in-memory-paths';

Expand Down Expand Up @@ -41,13 +42,17 @@ export async function deleteItemPlaceholder({ ctx, type, remote, locals }: Props
return;
}

const nonPlaceholderItem = await Addon.getFirstNonPlaceholder({ parentPath: local.path });
let nonPlaceholderItem: string | undefined;

const time = await measurePerfomance(async () => {
nonPlaceholderItem = await Addon.getFirstNonPlaceholder({ parentPath: local.path });
});

if (nonPlaceholderItem) {
ctx.logger.debug({ msg: 'Folder cannot be deleted because it contains a non placeholder item', nonPlaceholderItem });
ctx.logger.debug({ msg: 'Folder cannot be deleted because it contains a non placeholder item', time, nonPlaceholderItem });
return;
} else {
ctx.logger.debug({ msg: 'Folder can be deleted, all items are placeholders' });
ctx.logger.debug({ msg: 'Folder can be deleted, all items are placeholders', time });
}

/**
Expand All @@ -65,9 +70,7 @@ export async function deleteItemPlaceholder({ ctx, type, remote, locals }: Props
const trashPath = join(trashDir, randomUUID());
// Move operations are not allowed across different volumes.
await rename(local.path, trashPath);

const { default: trash } = await import('trash');
await trash(trashPath);
await rm(trashPath, { recursive: true, force: true });
} catch (error) {
ctx.logger.error({ msg: 'Error deleting placeholder', path: remote.absolutePath, type, error });
}
Expand Down
2 changes: 2 additions & 0 deletions src/infra/sqlite/services/file.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createOrUpdate } from './file/create-or-update';
import { createOrUpdateBatch } from './file/create-or-update-batch';
import { getBetweenUuids } from './file/get-between-uuids';
import { getByName } from './file/get-by-name';
import { getByParentUuid } from './file/get-by-parent-uuid';
import { getByUuid } from './file/get-by-uuid';
import { getByWorkspaceId } from './file/get-by-workspace-id';
import { updateByUuid } from './file/update-by-uuid';
Expand All @@ -10,6 +11,7 @@ export const FileModule = {
getByName,
getByUuid,
getBetweenUuids,
getByParentUuid,
getByWorkspaceId,
createOrUpdate,
createOrUpdateBatch,
Expand Down
16 changes: 8 additions & 8 deletions src/infra/sqlite/services/file/create-or-update-batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ describe('create-or-update-batch', () => {
};
});

it('should ignore if no files', () => {
it('should ignore if no files', async () => {
// Given
props.files = [];
// When
const error = createOrUpdateBatch(props);
const error = await createOrUpdateBatch(props);
// Then
expect(error).toBeUndefined();
expect({ ...db.prepare('SELECT COUNT(*) FROM drive_file').get() }).toStrictEqual({ 'COUNT(*)': 0 });
});

it('should insert new files', () => {
it('should insert new files', async () => {
// When
const error = createOrUpdateBatch(props);
const error = await createOrUpdateBatch(props);
// Then
expect(error).toBeUndefined();
expect({ ...db.prepare('SELECT COUNT(*) FROM drive_file').get() }).toStrictEqual({ 'COUNT(*)': 450 });
Expand All @@ -72,24 +72,24 @@ describe('create-or-update-batch', () => {
});
});

it('should update existing files', () => {
it('should update existing files', async () => {
// Given
props.files[1].uuid = 'uuid0';
props.files[1].plainName = 'file';
// When
const error = createOrUpdateBatch(props);
const error = await createOrUpdateBatch(props);
// Then
expect(error).toBeUndefined();
expect({ ...db.prepare('SELECT COUNT(*) FROM drive_file').get() }).toStrictEqual({ 'COUNT(*)': 449 });
expect({ ...db.prepare('SELECT COUNT(*) FROM drive_file WHERE uuid = ?').get('uuid0') }).toStrictEqual({ 'COUNT(*)': 1 });
expect({ ...db.prepare('SELECT COUNT(*) FROM drive_file WHERE uuid = ?').get('uuid1') }).toStrictEqual({ 'COUNT(*)': 0 });
});

it('should return UNKNOWN when error is thrown', () => {
it('should return UNKNOWN when error is thrown', async () => {
// Given
props.files.push({} as any);
// When
const error = createOrUpdateBatch(props);
const error = await createOrUpdateBatch(props);
// Then
expect(error?.code).toBe('UNKNOWN');
expect({ ...db.prepare('SELECT COUNT(*) FROM drive_file').get() }).toStrictEqual({ 'COUNT(*)': 400 });
Expand Down
15 changes: 4 additions & 11 deletions src/infra/sqlite/services/file/create-or-update-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { upsertQuery } from './queries';

const BATCH_SIZE = 100;

type Props = {
files: DriveFile[];
};

export function createOrUpdateBatch({ files }: Props) {
export async function createOrUpdateBatch({ files }: { files: DriveFile[] }) {
if (files.length === 0) return;

try {
Expand Down Expand Up @@ -39,15 +35,12 @@ export function createOrUpdateBatch({ files }: Props) {
});
}
db.exec('COMMIT');

await new Promise((resolve) => setImmediate(resolve));
}
} catch (error) {
db.exec('ROLLBACK');
logger.error({
msg: 'Error batch creating or updating files',
count: files.length,
error,
});

logger.error({ msg: 'Error batch creating or updating files', count: files.length, error });
return new SqliteError('UNKNOWN', error);
}
}
Loading
Loading