• RoundSparrow @ BT@bulletintree.comOPM
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    With performance enhancement in mind…

    when listing a single community, filtering logic should be more open-ended, especially if community has little content.

    Changes:

    1. Controversial should be consistent with Hot and Active that when it runs out of data it falls back to published DESC.
    2. This makes “published DESC” a consistent sorting pattern for every situation except “Old” and “NewComments”.
        query = match options.sort.unwrap_or(SortType::Hot) {
          SortType::Active => query
            .then_order_by(post_aggregates::hot_rank_active.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::Hot => query
            .then_order_by(post_aggregates::hot_rank.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::Controversial => query
            .then_order_by(post_aggregates::controversy_rank.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::New => query.then_order_by(post_aggregates::published.desc()),
          SortType::Old => query.then_order_by(post_aggregates::published.asc()),
          SortType::NewComments => query.then_order_by(post_aggregates::newest_comment_time.desc()),
          SortType::MostComments => query
            .then_order_by(post_aggregates::comments.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopAll => query
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopYear => query
            .filter(post_aggregates::published.gt(now - 1.years()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopMonth => query
            .filter(post_aggregates::published.gt(now - 1.months()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopWeek => query
            .filter(post_aggregates::published.gt(now - 1.weeks()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopDay => query
            .filter(post_aggregates::published.gt(now - 1.days()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopHour => query
            .filter(post_aggregates::published.gt(now - 1.hours()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopSixHour => query
            .filter(post_aggregates::published.gt(now - 6.hours()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopTwelveHour => query
            .filter(post_aggregates::published.gt(now - 12.hours()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopThreeMonths => query
            .filter(post_aggregates::published.gt(now - 3.months()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopSixMonths => query
            .filter(post_aggregates::published.gt(now - 6.months()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
          SortType::TopNineMonths => query
            .filter(post_aggregates::published.gt(now - 9.months()))
            .then_order_by(post_aggregates::score.desc())
            .then_order_by(post_aggregates::published.desc()),
        };