Skip to content

Modifications to SqliteStorage to allow for custom filepaths#77

Merged
ErikBjare merged 2 commits intomasterfrom
dev/db-fix
May 21, 2019
Merged

Modifications to SqliteStorage to allow for custom filepaths#77
ErikBjare merged 2 commits intomasterfrom
dev/db-fix

Conversation

@ErikBjare
Copy link
Member

I needed this in ActivityWatch/aw-server#50

if (self.last_commit - datetime.now()) > timedelta(seconds=10):
if self.enable_lazy_commit:
self.num_uncommited_statements += num_statements
if self.num_uncommited_statements > 10:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why lower it from 50 to 10?

And why do you need the enable_lazy_commit at all? It should work transparently?

Copy link
Member Author

@ErikBjare ErikBjare May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the 50 to 10 was accidental. Fixed.

enable_lazy_commit=True effectively makes the code asynchronous, which wasn't acceptable for a use-case I had (sync).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood that the use-case was sync, but why do you really need it?

Why do you need the absolute latest event? If you actually do, can't you instead force a commit when you actually need it like when using the REST API?

Copy link
Member Author

@ErikBjare ErikBjare May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need the absolute latest event?

Because I'm checking for the latest sent event sometimes, to know which events to send (I'd need to know about eventual uncommitted events).

If you actually do, can't you instead force a commit when you actually need it like when using the REST API?

I am calling it through the ServerAPI class in aw_server/api.py, and there doesn't seem to be any commit done through the REST API? How would you force a commit through the REST API?

Copy link
Member

@johan-bjareholt johan-bjareholt May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's weird, because I definitely didn't (That's why I did this in the first place). I'll take a closer look at it.

Copy link
Member

@johan-bjareholt johan-bjareholt May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's because you are running it as a seperate process?

Same thing here as with aw-server-rust, you should not be accessing a SQLite database from multiple threads or processes. This can corrupt the database if not configured properly.

Copy link
Member Author

@ErikBjare ErikBjare May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's because you are running it as a seperate process?

I'm not, I'm instantiating two ServerAPI objects with two different SqliteDatastore objects (with different db paths) in the same process and thread.

I've reproduced the issue by setting enable_lazy_commit=True, not sure what is going wrong, only seems to happen if process dies shortly after commit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't figure it out, I'm going ahead and merging this anyway.

@codecov
Copy link

codecov bot commented May 6, 2019

Codecov Report

Merging #77 into master will increase coverage by 0.14%.
The diff coverage is 76.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #77      +/-   ##
==========================================
+ Coverage   94.97%   95.11%   +0.14%     
==========================================
  Files          33       33              
  Lines        1551     1598      +47     
  Branches      233      293      +60     
==========================================
+ Hits         1473     1520      +47     
- Misses         46       47       +1     
+ Partials       32       31       -1
Impacted Files Coverage Δ
aw_datastore/migration.py 73.52% <100%> (+2.94%) ⬆️
aw_datastore/storages/sqlite.py 96.62% <73.33%> (-1.98%) ⬇️
aw_analysis/query2.py 99.71% <0%> (+0.67%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 924605a...bacf2d7. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented May 6, 2019

Codecov Report

Merging #77 into master will increase coverage by 0.14%.
The diff coverage is 76.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #77      +/-   ##
==========================================
+ Coverage   94.97%   95.11%   +0.14%     
==========================================
  Files          33       33              
  Lines        1551     1598      +47     
  Branches      233      293      +60     
==========================================
+ Hits         1473     1520      +47     
- Misses         46       47       +1     
+ Partials       32       31       -1
Impacted Files Coverage Δ
aw_datastore/migration.py 73.52% <100%> (+2.94%) ⬆️
aw_datastore/storages/sqlite.py 96.62% <73.33%> (-1.98%) ⬇️
aw_analysis/query2.py 99.71% <0%> (+0.67%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 924605a...bacf2d7. Read the comment docs.

@ErikBjare ErikBjare merged commit 61b1764 into master May 21, 2019
@ErikBjare ErikBjare deleted the dev/db-fix branch May 21, 2019 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants