Fix sessionid null error when resuming incremental parsing

When parsing resumes from an offset (mid-file), the "Start Log" line
was already processed in a previous run, leaving current_session_id
as None. Added get_or_create_session() to look up or create a session
when resuming from a non-zero offset.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-12-18 10:31:22 -05:00
parent 5bb142e33c
commit 0f78f76410

View File

@@ -230,6 +230,20 @@ class UDCParser:
return {'fileid': row['fileid'], 'offset': row['lastoffset'], 'size': row['filesize']} return {'fileid': row['fileid'], 'offset': row['lastoffset'], 'size': row['filesize']}
return {'fileid': None, 'offset': 0, 'size': 0} return {'fileid': None, 'offset': 0, 'size': 0}
def get_or_create_session(self, filepath: str, machine_number: str) -> int:
"""Get existing session for this file or create a new one for incremental parsing"""
basename = os.path.basename(filepath)
# Look for existing session for this file
self.cursor.execute(
"SELECT sessionid FROM udcsessions WHERE logfilename = %s ORDER BY sessionid DESC LIMIT 1",
(basename,)
)
row = self.cursor.fetchone()
if row:
return row['sessionid']
# No existing session, create one with current timestamp
return self.create_session(filepath, machine_number, datetime.now())
def update_file_state(self, filepath: str, machine_number: str, offset: int, filesize: int): def update_file_state(self, filepath: str, machine_number: str, offset: int, filesize: int):
"""Update the file state after parsing""" """Update the file state after parsing"""
self.cursor.execute( self.cursor.execute(
@@ -565,6 +579,11 @@ class UDCParser:
# Reset state # Reset state
self.current_session_id = None self.current_session_id = None
# If resuming from offset, get or create session immediately
# (we may not encounter a "Start Log" line when resuming mid-file)
if start_offset > 0:
self.current_session_id = self.get_or_create_session(filepath, machine_number)
self.current_partrun_id = None self.current_partrun_id = None
self.current_timestamp = None self.current_timestamp = None
self.current_badge = None self.current_badge = None