Skip to content

Commit

Permalink
NXDRIVE-2019: Improve database queries
Browse files Browse the repository at this point in the history
A small naive benchmark: Direct Transfer a folder containing 100 files.

- Before: ~ 281 req/s
- After:  ~ 352 req/s

From the UX POV, it feels like a significant gain on the overall upload speed.
  • Loading branch information
Mickaël Schoentgen authored and BoboTiG committed Aug 27, 2020
1 parent 09fbfda commit b847ecb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 2 additions & 0 deletions docs/changes/4.4.5.md
Expand Up @@ -99,6 +99,8 @@ Release date: `2020-xx-xx`
- Removed `Engine.get_remote_url()`. Use `server_url` attribute instead.
- Added `Engine.have_folder_upload`
- Removed `Engine.remove_staled_transfers()`
- Added `limit` keyword argument to `EngineDAO.get_dt_uploads_raw()`
- Changed the return type of `EngineDAO.get_dt_uploads_raw()` from `Generator[Dict[str, Any], None, None]` to `List[Dict[str, Any]]`
- Removed `Manager.get_tracker_id()`. Use `tracker.uid` attribute instead.
- Added `username` argument to `QMLDriveApi.update_token()`
- Removed `QMLDriveApi.get_tracker_id()`
Expand Down
16 changes: 9 additions & 7 deletions nxdrive/engine/dao/sqlite.py
Expand Up @@ -9,6 +9,7 @@
from contextlib import suppress
from datetime import datetime
from logging import getLogger
from os.path import basename
from pathlib import Path
from sqlite3 import (
Connection,
Expand Down Expand Up @@ -2246,27 +2247,28 @@ def get_dt_uploads(self) -> Generator[Upload, None, None]:
batch=json.loads(res.batch),
)

def get_dt_uploads_raw(self) -> Generator[Dict[str, Any], None, None]:
def get_dt_uploads_raw(self, limit: int = 1) -> List[Dict[str, Any]]:
"""
Retrieve all Direct Transfer items.
Return a simple dict to improve GUI performances (instead of Upload objects).
"""
con = self._get_read_connection()
c = con.cursor()
for res in c.execute(
"SELECT * FROM Uploads WHERE is_direct_transfer = 1"
).fetchall():
path = Path(res.path)
yield {
return [
{
"uid": res.uid,
"name": path.name,
"name": basename(res.path), # More efficient than Path(res.path).name
"filesize": res.filesize,
"status": TransferStatus(res.status),
"engine": res.engine,
"progress": res.progress or 0.0,
"remote_parent_path": res.remote_parent_path,
"remote_parent_ref": res.remote_parent_ref,
}
for res in c.execute(
f"SELECT * FROM Uploads WHERE is_direct_transfer = 1 LIMIT {limit}"
).fetchall()
]

def get_downloads_with_status(self, status: TransferStatus) -> List[Download]:
return [d for d in self.get_downloads() if d.status == status]
Expand Down
11 changes: 2 additions & 9 deletions nxdrive/gui/api.py
Expand Up @@ -207,15 +207,8 @@ def get_transfers(self, dao: EngineDAO) -> List[Dict[str, Any]]:
return result

def get_direct_transfer_items(self, dao: EngineDAO) -> List[Dict[str, Any]]:
limit = 5 # 5 files are displayed in the DT window
result: List[Dict[str, Any]] = []

for count, transfer in enumerate(dao.get_dt_uploads_raw()):
if count >= limit:
break
result.append(transfer)

return result
# 5 files are displayed in the DT window
return dao.get_dt_uploads_raw(limit=5)

@pyqtSlot(str, str, int, float, bool)
def pause_transfer(
Expand Down

0 comments on commit b847ecb

Please sign in to comment.