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

CommunityLanguage::read() should return empty vec if all languages are selected #2495

Closed
Nutomic opened this issue Oct 13, 2022 · 2 comments
Closed

Comments

@Nutomic
Copy link
Member

Nutomic commented Oct 13, 2022

Right now it just returns a list of all languages in that case, which means that the following command returns a total of 700 lines, listing all the languages.
curl -H 'Accept: application/activity+json' https://enterprise.lemmy.ml/c/main | jq .language

This doesnt make any sense, it should just return an empty vec if all languages are enabled in db, analogue to how CommunityLanguage::update() called with empty vec means that all languages should be enabled. The same goes for LocalUserLanguage::read and SiteLanguage::read.

However im not sure how to write a query which achieves this.

@dessalines
Copy link
Member

dessalines commented Oct 13, 2022

The site_language and community_language tables do need to be populated, otherwise joins won't work. If they are equivalent tho, you could just turn them into empty vectors in code.

@Nutomic
Copy link
Member Author

Nutomic commented Oct 13, 2022

I dont want to change anything about the way data is stored in the db, i just want to change how its returned from read() functions. In Rust it would look like this:

  pub fn read(conn: &mut PgConnection, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
    use crate::schema::{language::dsl as language, site_language::dsl as site_language};

    let site_languages = site_language::site_language
      .filter(site_language::site_id.eq(for_site_id))
      .select(site_language::language_id)
      .load(conn)?;
    let all_languages: Vec<LanguageId> = language::language.select(language::id).load(conn)?;

    if site_languages.len() == all_languages.len() {
      Ok(vec![])
    } else {
      Ok(site_languages)
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants