Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement language tags for site/community in db and api #2434

Merged
merged 13 commits into from
Oct 6, 2022

Conversation

Nutomic
Copy link
Member

@Nutomic Nutomic commented Sep 8, 2022

Check all the commit messages for a list of changes.

@Nutomic Nutomic force-pushed the site-and-community-languages branch 3 times, most recently from c703d13 to de90e5b Compare September 9, 2022 20:05
@Nutomic
Copy link
Member Author

Nutomic commented Sep 12, 2022

I think instead of Vec<LanguageId>, it would make sense to use some kind of Set<LanguageId>, as items dont need to be ordered, and set directly provides an intersect() method which we need. Problem is that a normal HashSet or BTreeSet needs more allocations and cpu work, so it would be necessary to pull in something like tinyset. Also, diesel only returns vec for db queries, it seems there is no way to get another collection without manual conversion. So probably not worth the effort.

@Nutomic Nutomic force-pushed the site-and-community-languages branch from 28c4b01 to f1388e0 Compare September 12, 2022 13:48
@Nutomic Nutomic marked this pull request as ready for review September 12, 2022 14:13
@Nutomic Nutomic requested a review from dessalines as a code owner September 12, 2022 14:13
@Nutomic
Copy link
Member Author

Nutomic commented Sep 12, 2022

This should be ready to merge. Still needs api tests (which require updated lemmy-js-client), and a lot of additional testing (during and after lemmy-ui implementation of this feature). Also need to test that db upgrades are working fine.

@Nutomic
Copy link
Member Author

Nutomic commented Sep 14, 2022

Last commit is broken, adding the list of languages to CommunityView seems tricky.

scripts/test.sh Outdated Show resolved Hide resolved
crates/db_schema/src/impls/actor_language.rs Show resolved Hide resolved
crates/db_schema/src/impls/actor_language.rs Outdated Show resolved Hide resolved
crates/api_crud/src/post/create.rs Outdated Show resolved Hide resolved
crates/api_crud/src/comment/update.rs Outdated Show resolved Hide resolved
crates/db_schema/src/impls/actor_language.rs Outdated Show resolved Hide resolved
return Err(LemmyError::from_message("language_not_allowed"));
}
blocking(context.pool(), move |conn| {
CommunityLanguage::update(conn, languages, community_id)
Copy link
Member

Choose a reason for hiding this comment

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

You can delete the subset check above, and just make sure CommunityLanguage::update is doing the subset in SQL by reading from SiteLanguages.

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean as part of the insert statement? How would that work in sql?

Copy link
Member

Choose a reason for hiding this comment

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

No, I mean inside the CommunityLanguage::update( fn, where it looks like you are already reading the site languages anyway. Looks like since users are providing any list of languages, you do have to read the site languages from sql, but can do a .retain type thing in that function.

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 see, but i cant move the check in here because of LemmyError in return value. Then i would also have to return LemmyError from Community::create(), which is incompatible with the trait.

crates/api_crud/src/post/update.rs Outdated Show resolved Hide resolved
@Nutomic Nutomic force-pushed the site-and-community-languages branch from 171d714 to ddbc7b6 Compare September 30, 2022 13:41
@Nutomic Nutomic force-pushed the site-and-community-languages branch 2 times, most recently from 8ae41fc to 5aad293 Compare September 30, 2022 14:55
less Outdated Show resolved Hide resolved
Ok::<(Vec<LanguageId>, Vec<LanguageId>, LanguageId), LemmyError>((
LocalUserLanguage::read(conn, local_user_id)?,
CommunityLanguage::read(conn, community_id)?,
Language::undetermined(),
Copy link
Member

Choose a reason for hiding this comment

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

Still an issue, this intersect logic should be done in SQL.

Copy link
Member Author

@Nutomic Nutomic Sep 30, 2022

Choose a reason for hiding this comment

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

I didnt finish addressing all the review comments yet, thats why they arent marked as resolved.

crates/db_schema/src/impls/actor_language.rs Outdated Show resolved Hide resolved
crates/db_views_actor/src/structs.rs Outdated Show resolved Hide resolved
return Err(LemmyError::from_message("language_not_allowed"));
}
blocking(context.pool(), move |conn| {
CommunityLanguage::update(conn, languages, community_id)
Copy link
Member

Choose a reason for hiding this comment

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

No, I mean inside the CommunityLanguage::update( fn, where it looks like you are already reading the site languages anyway. Looks like since users are providing any list of languages, you do have to read the site languages from sql, but can do a .retain type thing in that function.

crates/db_schema/src/impls/actor_language.rs Show resolved Hide resolved
@Nutomic Nutomic force-pushed the site-and-community-languages branch 4 times, most recently from 670d201 to aad0f16 Compare October 3, 2022 13:13
@Nutomic Nutomic marked this pull request as ready for review October 3, 2022 13:14
@Nutomic
Copy link
Member Author

Nutomic commented Oct 3, 2022

Okay made all the requested changes, except for the one in EditCommunity which is not possible due to error types.

@Nutomic Nutomic force-pushed the site-and-community-languages branch 2 times, most recently from e163855 to b33ab7d Compare October 3, 2022 13:33
Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

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

Nice job, the main thing I was concerned about was the intersection logic being in SQL. Feel free to merge once you add the TODO.

.limit(1)
.into_boxed();
site_language
.filter(site_id.eq_any(subquery))
Copy link
Member

Choose a reason for hiding this comment

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

Put a TODO here because this subquery is bad. This should go away once we add a site:local column.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

.filter(c::local)
.filter(sl::language_id.is_null())
.select(cl::language_id)
.get_results(conn)?;
Copy link
Member

Choose a reason for hiding this comment

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

Looks great, nice job.

.filter(ul::local_user_id.eq(local_user_id))
.filter(cl::community_id.eq(community_id))
.select(cl::language_id)
.get_results::<LanguageId>(conn)?;
Copy link
Member

Choose a reason for hiding this comment

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

Perfect. I think I need some way to get this info to the front end tho.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added this to GetCommunityView.

@dessalines
Copy link
Member

Once this is merged, I'll start on the front end for it.

@Nutomic Nutomic force-pushed the site-and-community-languages branch from 540b062 to a4e427e Compare October 6, 2022 08:26
@dessalines dessalines merged commit 2ef0f8f into main Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants