Skip to content

Commit

Permalink
Cleanup existing timeline entries (blakeblackshear#8495)
Browse files Browse the repository at this point in the history
* Cleanup existing timeline entries for beta users

* Formatting
  • Loading branch information
NickM-27 committed Nov 6, 2023
1 parent 2b2c831 commit 591b911
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions frigate/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ def vacuum_db(db: SqliteExtDatabase) -> None:
except PermissionError:
logger.error("Unable to write to /config to save DB state")

def cleanup_timeline_db(db: SqliteExtDatabase) -> None:
db.execute_sql(
"DELETE FROM timeline WHERE source_id NOT IN (SELECT id FROM event);"
)

try:
with open(f"{CONFIG_DIR}/.timeline", "w") as f:
f.write(str(datetime.datetime.now().timestamp()))
except PermissionError:
logger.error("Unable to write to /config to save DB state")

# Migrate DB location
old_db_path = DEFAULT_DB_PATH
if not os.path.isfile(self.config.database.path) and os.path.isfile(
Expand All @@ -294,6 +305,11 @@ def vacuum_db(db: SqliteExtDatabase) -> None:
router = Router(migrate_db)
router.run()

# this is a temporary check to clean up user DB from beta
# will be removed before final release
if not os.path.exists(f"{CONFIG_DIR}/.timeline"):
cleanup_timeline_db(migrate_db)

# check if vacuum needs to be run
if os.path.exists(f"{CONFIG_DIR}/.vacuum"):
with open(f"{CONFIG_DIR}/.vacuum") as f:
Expand Down

0 comments on commit 591b911

Please sign in to comment.