Split code into cargo workspaces #67

Merged
dessalines merged 5 commits from workspaces into master 2020-07-10 18:15:42 +00:00
Owner

It looks like clean build time increased a lot since we merged the federation branch. In my test it took 2:20 minutes. This PR decreases it to 1:28.

Still need to fix the tests.

Some more things to try:

  • remove lemmy_db dependency on lemmy_utils (so they can be compiled in parallel)
  • remove lemmy_utils dependency on actix_web
  • move api and apub into separate workspaces
  • remove diesel dependency on chrono
It looks like clean build time increased a lot since we merged the federation branch. In my test it took 2:20 minutes. This PR decreases it to 1:28. Still need to fix the tests. Some more things to try: - remove lemmy_db dependency on lemmy_utils (so they can be compiled in parallel) - remove lemmy_utils dependency on actix_web - move api and apub into separate workspaces - remove diesel dependency on chrono
Author
Owner

Fixed the test imports, but tests are still failing because the relative path config/defaults.hjson is not correct. I guess the best fix would be to make it so that tests dont need those files at all.

Note that tests need to be run with cargo test --all now, and format with cargo fmt --all.

Edit:: Not sure if this PR in its current state actually speeds things up, seeing 108s on master and 103s on this branch.

Fixed the test imports, but tests are still failing because the relative path `config/defaults.hjson` is not correct. I guess the best fix would be to make it so that tests dont need those files at all. Note that tests need to be run with `cargo test --all` now, and format with `cargo fmt --all`. Edit:: Not sure if this PR in its current state actually speeds things up, seeing 108s on master and 103s on this branch.
nutomic changed title from WIP: split code into cargo workspaces to split code into cargo workspaces 2020-07-09 13:41:35 +00:00
nutomic changed title from split code into cargo workspaces to Split code into cargo workspaces 2020-07-09 13:41:40 +00:00
Author
Owner

@dessalines Fixed the tests, rebased and ready to review. The first commit just moves files around and changes imports, so its much more important to review the second commit. In particular:

  • activity table uses text instead of jsonb now to remove that dependency, seems a bit cleaner (but we could revert that as it doesnt affect compile time at all)
  • test for lemmy_db::activity is failing because of the above change
  • claims and jwt handling moved from db to api
  • migrations moved out of the db
  • federation tests are completely broken for some reason

To be clear, even though this doesnt improve compilation time, I still think its very useful to merge this, as it makes for better separation of the code into mostly independent units.

@dessalines Fixed the tests, rebased and ready to review. The first commit just moves files around and changes imports, so its much more important to review the second commit. In particular: - activity table uses text instead of jsonb now to remove that dependency, seems a bit cleaner (but we could revert that as it doesnt affect compile time at all) - test for lemmy_db::activity is failing because of the above change - claims and jwt handling moved from db to api - migrations moved out of the db - federation tests are completely broken for some reason To be clear, even though this doesnt improve compilation time, I still think its very useful to merge this, as it makes for better separation of the code into mostly independent units.
Owner

I'll test / review this later today, but ya I don't wanna merge anything that breaks the tests, that's gotta be figured out.

I'll test / review this later today, but ya I don't wanna merge anything that breaks the tests, that's gotta be figured out.
Author
Owner

I think all thats needed is writing a migration for activity.data, converting it to TEXT. Based on this error: ERROR: column "data" is of type jsonb but expression is of type text at character 76.

I tried the following byt its not working:

ALTER TABLE activity ALTER COLUMN data TYPE TEXT USING (data::TEXT);
# Failed with: operator does not exist: text ->> text
I think all thats needed is writing a migration for `activity.data`, converting it to TEXT. Based on this error: `ERROR: column "data" is of type jsonb but expression is of type text at character 76`. I tried the following byt its not working: ``` ALTER TABLE activity ALTER COLUMN data TYPE TEXT USING (data::TEXT); # Failed with: operator does not exist: text ->> text ```
dessalines reviewed 2020-07-09 19:19:40 +00:00
dessalines left a comment
Owner

Looks good, I'm guessing the tests are failing due to the activity jsonb column stuff.

Also I'm not sure why but the docker-compose.ymls are all broken.

Looks good, I'm guessing the tests are failing due to the activity jsonb column stuff. Also I'm not sure why but the `docker-compose.yml`s are all broken.
@ -8,3 +8,3 @@
```bash
psql -U lemmy -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
export DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
Owner

This does need to be DATABASE_URL, because that's what diesel needs to run the migrations.

This does need to be `DATABASE_URL`, because that's what diesel needs to run the migrations.
@ -0,0 +1,15 @@
[package]
name = "lemmy_db"
version = "0.1.0"
authors = ["Felix Ableitner <me@nutomic.com>"]
Owner

add me too plz

add me too plz
Author
Owner

Of course, this is just what it auto-generated. Tbh I'm not sure its a good idea to have my email listed there in plaintext. Maybe we should put dev@lemmy.ml or something like that?

Of course, this is just what it auto-generated. Tbh I'm not sure its a good idea to have my email listed there in plaintext. Maybe we should put `dev@lemmy.ml` or something like that?
Owner

Ya, sounds good.

Ya, sounds good.
@ -0,0 +76,4 @@
pub fn update_ap_id(
conn: &PgConnection,
comment_id: i32,
apub_id: String,
Owner

Ah I see, this got moved to the other workspace.

Ah I see, this got moved to the other workspace.
Author
Owner

Yep it was one of the few apub things in the database, so it seemed cleaner to remove the apub dependency from the db.

Yep it was one of the few apub things in the database, so it seemed cleaner to remove the apub dependency from the db.
@ -0,0 +124,4 @@
}
pub fn get_database_url_from_env() -> Result<String, VarError> {
env::var("LEMMY_DATABASE_URL")
Owner

Is there any way to import the settings here? This is less than ideal bc if we ever reformat the settings hjson, we'll have to track this down at run-time.

Is there any way to import the settings here? This is less than ideal bc if we ever reformat the settings `hjson`, we'll have to track this down at run-time.
Author
Owner

Then I would probably have to make a separate workspace just for settings. This way seems much cleaner because we want things to be in parallel as much as possible.

But I will add a comment about that or something.

Then I would probably have to make a separate workspace just for settings. This way seems much cleaner because we want things to be in parallel as much as possible. But I will add a comment about that or something.
Owner

Ya, a comment is good enough for now. Surprising that the settings doesn't get used in both of these.

Ya, a comment is good enough for now. Surprising that the settings doesn't get used in both of these.
Author
Owner

Actually I thought I removed the check of LEMMY_DATABASE_URL in settings, thats not needed. Will get rid of that, so DATABASE_URL here in db will be the only env var for that.

Actually I thought I removed the check of `LEMMY_DATABASE_URL` in settings, thats not needed. Will get rid of that, so `DATABASE_URL` here in db will be the only env var for that.
@ -0,0 +2,4 @@
activity (id) {
id -> Int4,
user_id -> Int4,
data -> Text,
Owner

I don't think you can just overwrite it like that, and either way it gets re-written every time you run a migration.

I don't think you can just overwrite it like that, and either way it gets re-written every time you run a migration.
@ -0,0 +1,23 @@
[package]
name = "lemmy_utils"
version = "0.1.0"
authors = ["Felix Ableitner <me@nutomic.com>"]
Owner

same

same
@ -0,0 +70,4 @@
let claims: Claims = Claims::decode(&jwt).expect("Invalid token").claims;
User_::read(&conn, claims.id)
}
}
Owner

This does make sense to be split out. Soon I'm gonna remove almost all this stuff from the jwt, and just pull it, in order to make the settings more portable.

This does make sense to be split out. Soon I'm gonna remove almost all this stuff from the jwt, and just pull it, in order to make the settings more portable.
Author
Owner

Updated. See the last commit for details.

However, test_mentions_regex is failing, because WEBFINGER_COMMUNITY_REGEX reads a field from settings. Problem is that during tests, the path config/defaults.hjson is interpreted as relative to the lemmy_utils folder, meaning it tries to read from server/lemmy_utils/config/defaults.hjson (which doesnt exist). So either we need to make it so the test doesnt read from settings, or we add another config file in that location.

Federation tests are fixed, except "create test comment" is failing for some reason (I will investigate later).

I also had to change all occurences of LEMMY_DATABASE_URL to DATABASE_URL, which is a breaking change. I could also add a check for the old env var to stay backwards compatible.

Updated. See the last commit for details. However, `test_mentions_regex` is failing, because `WEBFINGER_COMMUNITY_REGEX` reads a field from settings. Problem is that during tests, the path `config/defaults.hjson` is interpreted as relative to the lemmy_utils folder, meaning it tries to read from `server/lemmy_utils/config/defaults.hjson` (which doesnt exist). So either we need to make it so the test doesnt read from settings, or we add another config file in that location. Federation tests are fixed, except "create test comment" is failing for some reason (I will investigate later). I also had to change all occurences of `LEMMY_DATABASE_URL` to `DATABASE_URL`, which is a breaking change. I could also add a check for the old env var to stay backwards compatible.
Owner

However, test_mentions_regex is failing, because WEBFINGER_COMMUNITY_REGEX reads a field from settings. Problem is that during tests, the path config/defaults.hjson is interpreted as relative to the lemmy_utils folder, meaning it tries to read from server/lemmy_utils/config/defaults.hjson (which doesnt exist).

Can't we just move these two below up a dir? Or make sure its possible to run the utils tests from the parent dir. Or possibly symlinks might work.

static CONFIG_FILE_DEFAULTS: &str = "config/defaults.hjson";
static CONFIG_FILE: &str = "config/config.hjson";

I also had to change all occurences of LEMMY_DATABASE_URL to DATABASE_URL, which is a breaking change. I could also add a check for the old env var to stay backwards compatible.

That shouldn't be necessary, its fine as it was. DATABASE_URL is something that only diesel needs.

Also all the docker builds fail w/ this:

-----
 > [rust 9/13] RUN cargo build:
#18 1.109 error: failed to read `/app/server/lemmy_utils/Cargo.toml`
#18 1.109
#18 1.109 Caused by:
#18 1.109   No such file or directory (os error 2)
------
> However, test_mentions_regex is failing, because WEBFINGER_COMMUNITY_REGEX reads a field from settings. Problem is that during tests, the path config/defaults.hjson is interpreted as relative to the lemmy_utils folder, meaning it tries to read from server/lemmy_utils/config/defaults.hjson (which doesnt exist). Can't we just move these two below up a dir? Or make sure its possible to run the utils tests from the parent dir. Or possibly symlinks might work. ``` static CONFIG_FILE_DEFAULTS: &str = "config/defaults.hjson"; static CONFIG_FILE: &str = "config/config.hjson"; ``` > I also had to change all occurences of LEMMY_DATABASE_URL to DATABASE_URL, which is a breaking change. I could also add a check for the old env var to stay backwards compatible. That shouldn't be necessary, its fine as it was. DATABASE_URL is something that only diesel needs. Also all the docker builds fail w/ this: ``` ----- > [rust 9/13] RUN cargo build: #18 1.109 error: failed to read `/app/server/lemmy_utils/Cargo.toml` #18 1.109 #18 1.109 Caused by: #18 1.109 No such file or directory (os error 2) ------ ```
Author
Owner

Should be good now, all tests are passing (including federation). Please consider squashing before merging.

Should be good now, all tests are passing (including federation). Please consider squashing before merging.
dessalines merged commit 80aef61aed into master 2020-07-10 18:15:42 +00:00
nutomic deleted branch workspaces 2020-07-10 19:41:50 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: LemmyNet/lemmy#67
No description provided.