Count items in database as much as possible #344
No reviewers
Labels
No labels
A: API
A: Backend
A: Federation
A: Front-End
A: I18N
A: Meta
A: Security
Build
C: Bug
C: Discussion
C: Enhancement
C: Feature
Compatibility
Dependency
Design
Documentation
Good first issue
Help welcome
Mobile
Rendering
S: Blocked
S: Duplicate
S: Incomplete
S: Instance specific
S: Invalid
S: Needs Voting/Discussion
S: Ready for review
Suggestion
S: Voted on Loomio
S: Wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Plume/Plume#344
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "count-in-db"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Codecov Report
0% <0%> (ø)
12.01% <0%> (-0.13%)
0% <0%> (ø)
0% <0%> (ø)
0% <0%> (ø)
0% <0%> (ø)
0% <0%> (ø)
0% <0%> (ø)
0% <0%> (ø)
0% <0%> (ø)
Continue to review full report at Codecov.
Things I commented are further optimizations possible, however they're not strictly needed to be implemented for this to be merged. Actually I don't even know if it would give better performance as optimizations I proposed can be proved equivalent to current implementation with what DBMSs know about our model, so they might do the optimization themselves
I wonder if the second query is useful, I think
count()
ing on the first one is sufficient, except in case where :.select(blog_authors::author_id)
is removed too, if it is not then multiple (id_X,blog_1,author_1) would be mapped to only one (author_1) anyway. Hope I'm clear enough)ordering then counting is useless, I guess PostgreSQL would see it and optimize that away, but I also think SQLite is too dumb to do the same, so it might be shorter and faster to remove that
Yes, I just copy/pasted another function. I'll change that.
OK, I'll change it (and yes you were clear enough 🙂)
Love it when an issue is only reproducible on one db backend. It might be because sqlite don't enforce some constraints by default, we could enabled
PRAGMA foreign_keys = ON;
, but I wonder what changes to make this test failwe have that enabled — on the
users
table — not sure if/how we enable it by default.maybe we're finally using that constraint? 😅
@igalic I think we only set it in a migration, this property is not stored so we need to set it somehow at each Plume launch, and this is a global var, so it was enabled for all tables (but only until the migration end)
unlike (some) other
pragma
instructions, it's not storable… it's, as you say, per connection or per transaction.So perhaps the diesel sqlite driver has something we can turn on by default
i checked, it can't
but maybe we can wrap the query functions with a
begin transaction; pragma foreign_keys = on;
@ -41,0 +48,4 @@
sql_query("PRAGMA foreign_keys = on;").execute(conn)
.map(|_| ())
.map_err(|_| ConnError::ConnectionError(ConnectionError::BadConnection(String::from("PRAGMA foreign_keys = on failed"))))
}
oh, I was searching for exactly that but did not find it
@ -41,0 +48,4 @@
sql_query("PRAGMA foreign_keys = on;").execute(conn)
.map(|_| ())
.map_err(|_| ConnError::ConnectionError(ConnectionError::BadConnection(String::from("PRAGMA foreign_keys = on failed"))))
}
Looks like it is not working at all🙃 nvm I think I found the issue@ -41,0 +48,4 @@
sql_query("PRAGMA foreign_keys = on;").execute(conn)
.map(|_| ())
.map_err(|_| ConnError::ConnectionError(ConnectionError::BadConnection(String::from("PRAGMA foreign_keys = on failed"))))
}
I think your changes are only affecting the web interface, which is at the same time the most important part, and the one not tested by travis 🙃
I've tested doing similar changes in plume_model::lib:tests::db (adding
sql_query("PRAGMA foreign_keys = on;").execute(&conn).unwrap();
) which seems to work fine"bfore", "after bfore", "after after", then is it "after after bfore" or "after after after"?
(joking about the comments, but they should be removed actually, I guess you forgot to)
Oops 😬