Skip to content

Commit 12e12b5

Browse files
committed
only index new directories in _scan_dir()
1 parent 56b7668 commit 12e12b5

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

jupyter_server/services/contents/fileidmanager.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
class StatStruct:
12-
empty = True
1312
ino: int
1413
crtime: Optional[int]
1514
mtime: int
@@ -64,8 +63,8 @@ def __init__(self, *args, **kwargs):
6463
")"
6564
)
6665
self._index_all()
66+
# no need to index ino as it is autoindexed by sqlite via UNIQUE constraint
6767
self.con.execute("CREATE INDEX IF NOT EXISTS ix_Files_path ON Files (path)")
68-
self.con.execute("CREATE INDEX IF NOT EXISTS ix_Files_ino ON Files (ino)")
6968
self.con.execute("CREATE INDEX IF NOT EXISTS ix_Files_is_dir ON Files (is_dir)")
7069
self.con.commit()
7170

@@ -138,7 +137,8 @@ def _sync_dir(self, dir_path):
138137
stat_info = self._parse_raw_stat(entry.stat())
139138
id, is_dirty_dir = self._sync_file(entry.path, stat_info)
140139

141-
if id is None:
140+
# if entry is unindexed directory, create new record
141+
if stat_info.is_dir and id is None:
142142
self._create(entry.path, stat_info)
143143

144144
# sync dirty dir contents if it is either unindexed or
@@ -201,13 +201,11 @@ def _normalize_path(self, path):
201201
path = os.path.normpath(path)
202202
return path
203203

204-
def _parse_raw_stat(self, raw_stat, stat_info=None):
204+
def _parse_raw_stat(self, raw_stat):
205205
"""Accepts an `os.stat_result` object and returns a `StatStruct`
206-
object. Writes to `stat_info` argument if passed."""
207-
if stat_info is None:
208-
stat_info = StatStruct()
206+
object."""
207+
stat_info = StatStruct()
209208

210-
stat_info.empty = False
211209
stat_info.ino = raw_stat.st_ino
212210
stat_info.crtime = (
213211
raw_stat.st_ctime_ns
@@ -225,14 +223,12 @@ def _parse_raw_stat(self, raw_stat, stat_info=None):
225223
def _stat(self, path):
226224
"""Returns stat info on a path in a StatStruct object.Returns None if
227225
file does not exist at path."""
228-
stat_info = StatStruct()
229-
230226
try:
231227
raw_stat = os.stat(path)
232228
except OSError:
233229
return None
234230

235-
return self._parse_raw_stat(raw_stat, stat_info)
231+
return self._parse_raw_stat(raw_stat)
236232

237233
def _create(self, path, stat_info):
238234
"""Creates a record given its path and stat info. Returns the new file
@@ -300,6 +296,7 @@ def get_path(self, id):
300296
the ID does not exist in the Files table or if the corresponding path no
301297
longer has a file."""
302298
self._sync_all()
299+
self.con.commit()
303300
row = self.con.execute("SELECT path FROM Files WHERE id = ?", (id,)).fetchone()
304301
return row[0] if row else None
305302

0 commit comments

Comments
 (0)