pace-rs / pace

Mindful Time Tracking: Simplify Your Focus and Boost Productivity Effortlessly.
https://pace.cli.rs
GNU Affero General Public License v3.0
19 stars 0 forks source link

Long-Term Considerations Regarding Toml File Storage #97

Open simonsan opened 3 months ago

simonsan commented 3 months ago

Current situation

I initially implemented the storage model for the activity log based on the Toml file format. When we begin a new activity, we parse the log with all entries, and then we append it in memory to the vector and write the whole activity log back into the file.

When we end or update an activity, we do the same thing.

I think that has several disadvantages, e.g. when there is an error during writing back the file, it could be damaged and the activity log destroyed. Also, it will take longer and longer to parse it, with activities becoming more and more. I need to benchmark that, it could be negligible with a few thousand activities, which is unlikely to happen, as users might archive their activity log monthly when the archival feature is implemented.

I could refactor the entire model to an event based one, so the log file is really append-only and only writes to the end of the file. But I'm actually not sure if this makes sense at this point, because I want to implement the storage in a SQLite database soonish, which would make this obsolete. Because I don't think we want to do it event based in the database, as it's much easier to query for a record and update it or even batch update records.

The reason I initially used Toml was so users can edit it within their favourite text editor, and I found that kind of useful as I used that a lot to edit activities in bartib. I think this would become less useful, when I reimplement it in a way, that only events are stored. Because then it's not as easy to determine any more, what the actual status, duration etc. of an activity really is. To determine that, we would need to parse all activities in a certain time frame and then merge the events. Which will be much more complicated.

Pros And Cons

Current TOML-Based Storage Model:

Pros:

Cons:

Event-Based Append-Only Model:

Pros:

Cons:

Direct Transition to SQLite:

Pros:

Cons:

simonsan commented 3 months ago

That being said, I don't think it makes a lot of sense to invest time and energy to refactor to an append-only event-based model for the Toml storage at this point. I think the way to go is to implement the Storage traits for SQLiteStorage and use it as the default storage. Maybe it could make sense refactor the Toml storage to an append-only and event-based local event log, so we can sync from it to a future implementation of a DBMS e.g. PostgresStorage for multi-user/team environments. But even that could be easier to sync from SQLite.