Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Make repos sortable by size#44360

Merged
vdavid merged 17 commits into
mainfrom
dv/sortable-repos
Nov 17, 2022
Merged

Make repos sortable by size#44360
vdavid merged 17 commits into
mainfrom
dv/sortable-repos

Conversation

@vdavid

@vdavid vdavid commented Nov 14, 2022

Copy link
Copy Markdown
Contributor

Summary: This is an extension of the FilteredConnection component on the front end to allow for setting an order of the items, plus a tiny back-end change.

This is how the new UI looks:

UI preview

Goodies about the UI change:

  • The ordering feature is generic: it can be used wherever we use the FilteredConnection component.
  • Ordering by repo creation date (REPOSITORY_CREATED_AT) can be added in five minutes as an extra option if that adds value (plus it can be further extended with other fields quite easily)
  • a11y: It should be as accessible as the filter was.
  • The naming around filters was not right. The filter value was called "value" at several places, which was far too generic for what it did. This change improves naming.

Test plan

  • Tested the basic features manually; here is a 1.5-min UI demo of the final version.
  • I've added an integration test case and an end-to-end test case. (thanks to @eseliger and @mrnugget for helping me deliver this feature safely!)
  • I've added an index on the gitserver_repos.repo_size_bytes column, so the sorting should be performant even in the case of 500k+ repos. (thanks to @philipp-spiess for bringing this up, and @eseliger for his help!)

Also tested the API with this query (results):

query Repositories {
  repositories(orderBy: SIZE, descending: true) {
    totalCount,
    nodes {
      name,
      diskSizeBytes
    }
  }
}

@vdavid vdavid requested a review from mrnugget November 14, 2022 15:09
@cla-bot cla-bot Bot added the cla-signed label Nov 14, 2022
@vdavid

vdavid commented Nov 14, 2022

Copy link
Copy Markdown
Contributor Author

@mrnugget Question: Do you think making JoinGitserverRepos public is safe? So far, I've seen no reason not to do it, but I want to avoid leaking database package internals if it's unsafe.
I ultimately need gitserver_repos in the query, and there are already a lot of conditions that enable joining it. I can play with the front-end request to make sure one of these options is satisfied, and then joinGitserverRepos can remain private to the package.

@vdavid

vdavid commented Nov 14, 2022

Copy link
Copy Markdown
Contributor Author

This works now:

query Repositories {
  repositories(orderBy: SIZE, descending: true) {
    totalCount,
    nodes {
      name,
      diskSizeBytes
    }
  }
}

results

@sg-e2e-regression-test-bob

sg-e2e-regression-test-bob commented Nov 14, 2022

Copy link
Copy Markdown

Bundle size report 📦

Initial size Total size Async size Modules
0.01% (+0.22 kb) 0.01% (+1.11 kb) 0.01% (+0.89 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits e504976 and cc7bd73 or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@mrnugget

Copy link
Copy Markdown
Contributor

This works now:

Where in that query do you specify to sort by size? I only see descending: true but that could relate to any other field.

Comment thread internal/database/repos.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think you'll need to expose JoinGitserverRepos if you change this check here to check for opt.OrderBy == RepoListSize. I think that'd be cleaner.

@mrnugget

Copy link
Copy Markdown
Contributor

The results in your screenshot are not ordered by size. Easy to spot by looking at number of digits but also like this:

$ cat sizes.txt
1515174277
1203540
8003978
103056741
59657129
177629
$ cat sizes.txt | sort -n
177629
1203540
8003978
59657129
103056741
1515174277
$ cat sizes.txt | sort -nr
1515174277
103056741
59657129
8003978
1203540
177629

@vdavid

vdavid commented Nov 14, 2022

Copy link
Copy Markdown
Contributor Author

@mrnugget Shoot, not sure how I messed it up, but missed orderBy: SIZE.

Fixed it in the description and message above, and here is the correct screenshot: https://share.cleanshot.com/IL7G1q

@vdavid

vdavid commented Nov 14, 2022

Copy link
Copy Markdown
Contributor Author

Also works with the UI: https://share.cleanshot.com/ZapzF1 with a two-liner change. We can basically ship this 😉

@vdavid

vdavid commented Nov 14, 2022

Copy link
Copy Markdown
Contributor Author

Hey, @mrnugget, I did an experiment for the UI, which turned out to be quicker and nicer than I'd expected. I think it's quite nice overall, could be an easy win if we go with this: https://www.loom.com/share/536b50a954bb49659cf696552f494193

Extra goodies:

  • The ordering feature can be just used wherever we use the FilteredConnection component
  • Ordering by repo creation date (REPOSITORY_CREATED_AT) can be added in five minutes as an extra option if that adds value (plus it can be further extended with other fields quite easily now)
  • a11y: It should be as accessible as the filter was.
  • The naming around filters was not right. The filter value was called "value" at several places, which was far too generic for what it did. This change makes this part better documented as well.

Known caveats:

  • At small window widths, the original version looks broken, and the current version looks slightly even more broken. Probably needs a little CSS fix if we go with this version.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have an index on that column? If we sort by it, should we have one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've just checked it, and no, we don't have an index on it yet. I haven't looked into the performance aspect yet, but great point! I've now put it on my list to add the index as part of this PR. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch @philipp-spiess!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we get query plans for this from the dotcom database (dev-readonly account is in 1pass)? That table is very critically congested sadly

@vdavid vdavid Nov 16, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This whole file is basically a smart copy of FilterControl.tsx. I generally don't favor copy&paste programming, but when there are two of a thing (rather than three, four, ...), it's always a tricky call to decide how much to generalize.
In this case, I went with duplication because:

  • This is an old component that we may deprecate, so, honestly, I didn't want to invest a lot of time in it
  • Ordering and filtration are two different concepts, not the copy of the same thing. So if retained, they may evolve in different ways. So generalizing them might actually be a step backward.

The same reasoning applies to a few other changes in this PR.

@vdavid vdavid force-pushed the dv/sortable-repos branch 4 times, most recently from e43092d to ddf19b0 Compare November 16, 2022 13:58
@vdavid vdavid marked this pull request as ready for review November 16, 2022 14:00
@vdavid vdavid requested review from a team and 0xnmn November 16, 2022 14:00
@sourcegraph-bot

sourcegraph-bot commented Nov 16, 2022

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff cc7bd73...e504976.

Notify File(s)
@eseliger internal/database/repos.go
internal/database/repos_test.go
@unknwon internal/database/repos.go
internal/database/repos_test.go

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work. Query plan please! :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we get query plans for this from the dotcom database (dev-readonly account is in 1pass)? That table is very critically congested sadly

Comment thread internal/database/repos.go
@@ -0,0 +1,2 @@
CREATE INDEX IF NOT EXISTS gitserver_repo_size_bytes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indexes should usually be created concurrently

@@ -0,0 +1,2 @@
CREATE INDEX IF NOT EXISTS gitserver_repo_size_bytes
ON gitserver_repos USING btree (repo_size_bytes)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
ON gitserver_repos USING btree (repo_size_bytes)
ON gitserver_repos USING btree (repo_size_bytes);

Comment on lines +229 to +230
$orderBy: RepositoryOrderBy
$descending: Boolean

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know this already exists on main, but want to leave some thoughts on this pattern (maybe these thoughts are more for @philipp-spiess and @courier-new as they're working on standardized pagination etc):

I think this pattern encourages to set one value or the other, but not necessarily both, which feels undesirable.

Idea that would enforce that none or both values are set, and also makes ascending/descending more expressive (otherwise, what's the default here? descending: false => ascending?):

type Query {
  repositories(order: RepositoryOrderInput): RepositoryConnection!
}

enum OrderDirection {
  ASCENDING
  DESCENDING
}

input RepositoryOrderInput {
  orderBy: RepositoryOrderBy!
  direction: OrderDirection!
}

Comment thread cmd/frontend/graphqlbackend/repositories.go

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work!

@mrnugget mrnugget left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ship it!

@vdavid

vdavid commented Nov 17, 2022

Copy link
Copy Markdown
Contributor Author

@eseliger and I tested the performance of the new index. Huge difference, so thanks, @philipp-spiess for making sure we didn't miss this!

We tested with two queryies.

🥁 The contestants:

Just a "sort by size, desc"
SELECT repo.id,repo.name,repo.private,repo.external_id,repo.external_service_type,repo.external_service_id,repo.uri,repo.description,repo.fork,repo.archived,repo.stars,repo.created_at,repo.updated_at,repo.deleted_at,repo.metadata,repo.blocked,(SELECT json_object_agg(key, value) FROM repo_kvps WHERE repo_kvps.repo_id = repo.id),
(
	SELECT
		json_agg(
		json_build_object(
			'CloneURL', esr.clone_url,
			'ID', esr.external_service_id,
			'Kind', LOWER(svcs.kind)
		)
		)
	FROM external_service_repos AS esr
	JOIN external_services AS svcs ON esr.external_service_id = svcs.id
	WHERE
		esr.repo_id = repo.id
		AND
		svcs.deleted_at IS NULL
)

FROM repo
JOIN gitserver_repos gr ON gr.repo_id = repo.id
WHERE
	repo.deleted_at IS NULL AND repo.blocked IS NULL AND (TRUE)   -- Populates "queryConds"
	AND
	(
(
    -- Bypass authz
    TRUE
)
) -- Populates "authzConds"
ORDER BY gr.repo_size_bytes DESC LIMIT 21 OFFSET 0
Sorting by size, plus filtering for "%github%"
SELECT repo.id,repo.name,repo.private,repo.external_id,repo.external_service_type,repo.external_service_id,repo.uri,repo.description,repo.fork,repo.archived,repo.stars,repo.created_at,repo.updated_at,repo.deleted_at,repo.metadata,repo.blocked,(SELECT json_object_agg(key, value) FROM repo_kvps WHERE repo_kvps.repo_id = repo.id),
(
	SELECT
		json_agg(
		json_build_object(
			'CloneURL', esr.clone_url,
			'ID', esr.external_service_id,
			'Kind', LOWER(svcs.kind)
		)
		)
	FROM external_service_repos AS esr
	JOIN external_services AS svcs ON esr.external_service_id = svcs.id
	WHERE
		esr.repo_id = repo.id
		AND
		svcs.deleted_at IS NULL
)

FROM repo
JOIN gitserver_repos gr ON gr.repo_id = repo.id
WHERE
	repo.deleted_at IS NULL AND repo.blocked IS NULL AND (lower(name) LIKE "%github%")   -- Populates "queryConds"
	AND
	(
(
    -- Bypass authz
    TRUE
)
) -- Populates "authzConds"
ORDER BY gr.repo_size_bytes DESC LIMIT 21 OFFSET 0

👎 And the results, unindexed:

First query, unindexed: 32829.716 ms
                                                                                                    QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=2183377.62..2183688.33 rows=21 width=700) (actual time=32828.979..32829.378 rows=21 loops=1)
   ->  Result  (cost=2183377.62..100509007.64 rows=6645663 width=700) (actual time=32828.978..32829.373 rows=21 loops=1)
         ->  Sort  (cost=2183377.62..2199991.78 rows=6645663 width=636) (actual time=32828.346..32828.353 rows=21 loops=1)
               Sort Key: gr.repo_size_bytes DESC
               Sort Method: top-N heapsort  Memory: 52kB
               ->  Merge Join  (cost=6.68..2004200.00 rows=6645663 width=636) (actual time=0.117..28297.844 rows=6663241 loops=1)
                     Merge Cond: (repo.id = gr.repo_id)
                     ->  Index Scan using repo_pkey on repo  (cost=0.43..1085118.64 rows=6596456 width=628) (actual time=0.012..11698.299 rows=6663241 loops=1)
                           Filter: ((deleted_at IS NULL) AND (blocked IS NULL))
                           Rows Removed by Filter: 844050
                     ->  Index Scan using gitserver_repos_pkey on gitserver_repos gr  (cost=0.56..822034.27 rows=7531885 width=12) (actual time=0.102..12602.976 rows=7507291 loops=1)
         SubPlan 1
           ->  Aggregate  (cost=1.70..1.71 rows=1 width=32) (actual time=0.004..0.004 rows=1 loops=21)
                 ->  Index Only Scan using repo_kvps_pkey on repo_kvps  (cost=0.43..1.67 rows=8 width=42) (actual time=0.004..0.004 rows=0 loops=21)
                       Index Cond: (repo_id = repo.id)
                       Heap Fetches: 0
         SubPlan 2
           ->  Aggregate  (cost=13.07..13.08 rows=1 width=32) (actual time=0.042..0.042 rows=1 loops=21)
                 ->  Nested Loop  (cost=9.64..13.06 rows=1 width=58) (actual time=0.011..0.012 rows=1 loops=21)
                       ->  Index Scan using external_service_repos_repo_id_external_service_id_unique on external_service_repos esr  (cost=0.43..2.65 rows=1 width=51) (actual time=0.007..0.007 rows=1 loops=21)
                             Index Cond: (repo_id = repo.id)
                       ->  Bitmap Heap Scan on external_services svcs  (cost=9.20..10.32 rows=1 width=15) (actual time=0.003..0.003 rows=1 loops=21)
                             Recheck Cond: (id = esr.external_service_id)
                             Filter: (deleted_at IS NULL)
                             Heap Blocks: exact=21
                             ->  Bitmap Index Scan on external_services_pkey  (cost=0.00..9.20 rows=1 width=0) (actual time=0.001..0.001 rows=1 loops=21)
                                   Index Cond: (id = esr.external_service_id)
 Planning Time: 5.347 ms
 Execution Time: 32829.716 ms
(29 rows)
Second query, unindexed: 34892.949 ms
                                                                                                    QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=2212829.35..2213140.05 rows=21 width=700) (actual time=34892.504..34892.824 rows=21 loops=1)
   ->  Result  (cost=2212829.35..97558890.78 rows=6444279 width=700) (actual time=34892.503..34892.820 rows=21 loops=1)
         ->  Sort  (cost=2212829.35..2228940.05 rows=6444279 width=636) (actual time=34892.406..34892.409 rows=21 loops=1)
               Sort Key: gr.repo_size_bytes DESC
               Sort Method: top-N heapsort  Memory: 52kB
               ->  Merge Join  (cost=6.68..2039081.36 rows=6444279 width=636) (actual time=0.020..30638.558 rows=6362568 loops=1)
                     Merge Cond: (repo.id = gr.repo_id)
                     ->  Index Scan using repo_pkey on repo  (cost=0.43..1122499.22 rows=6396563 width=628) (actual time=0.011..17986.767 rows=6362568 loops=1)
                           Filter: ((deleted_at IS NULL) AND (blocked IS NULL) AND (lower((name)::text) ~~ '%github%'::text))
                           Rows Removed by Filter: 1144734
                     ->  Index Scan using gitserver_repos_pkey on gitserver_repos gr  (cost=0.56..822034.27 rows=7531885 width=12) (actual time=0.007..8738.426 rows=7507302 loops=1)
         SubPlan 1
           ->  Aggregate  (cost=1.70..1.71 rows=1 width=32) (actual time=0.004..0.004 rows=1 loops=21)
                 ->  Index Only Scan using repo_kvps_pkey on repo_kvps  (cost=0.43..1.67 rows=8 width=42) (actual time=0.003..0.003 rows=0 loops=21)
                       Index Cond: (repo_id = repo.id)
                       Heap Fetches: 0
         SubPlan 2
           ->  Aggregate  (cost=13.07..13.08 rows=1 width=32) (actual time=0.013..0.014 rows=1 loops=21)
                 ->  Nested Loop  (cost=9.64..13.06 rows=1 width=58) (actual time=0.009..0.009 rows=1 loops=21)
                       ->  Index Scan using external_service_repos_repo_id_external_service_id_unique on external_service_repos esr  (cost=0.43..2.65 rows=1 width=51) (actual time=0.004..0.004 rows=1 loops=21)
                             Index Cond: (repo_id = repo.id)
                       ->  Bitmap Heap Scan on external_services svcs  (cost=9.20..10.32 rows=1 width=15) (actual time=0.003..0.003 rows=1 loops=21)
                             Recheck Cond: (id = esr.external_service_id)
                             Filter: (deleted_at IS NULL)
                             Heap Blocks: exact=21
                             ->  Bitmap Index Scan on external_services_pkey  (cost=0.00..9.20 rows=1 width=0) (actual time=0.002..0.002 rows=1 loops=21)
                                   Index Cond: (id = esr.external_service_id)
 Planning Time: 0.965 ms
 Execution Time: 34892.949 ms
(29 rows)

👍 Indexed now:

First query, indexed: 3.288 ms
                                                                                                    QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.86..467.50 rows=21 width=700) (actual time=2.087..2.962 rows=21 loops=1)
   ->  Nested Loop  (cost=0.86..147191164.90 rows=6623989 width=700) (actual time=2.086..2.958 rows=21 loops=1)
         ->  Index Scan Backward using gitserver_repo_size_bytes on gitserver_repos gr  (cost=0.43..695608.67 rows=7507321 width=12) (actual time=0.013..0.451 rows=312 loops=1)
         ->  Index Scan using repo_pkey on repo  (cost=0.43..0.58 rows=1 width=628) (actual time=0.006..0.006 rows=0 loops=312)
               Index Cond: (id = gr.repo_id)
               Filter: ((deleted_at IS NULL) AND (blocked IS NULL))
               Rows Removed by Filter: 1
         SubPlan 1
           ->  Aggregate  (cost=1.70..1.71 rows=1 width=32) (actual time=0.003..0.003 rows=1 loops=21)
                 ->  Index Only Scan using repo_kvps_pkey on repo_kvps  (cost=0.43..1.67 rows=8 width=42) (actual time=0.002..0.002 rows=0 loops=21)
                       Index Cond: (repo_id = repo.id)
                       Heap Fetches: 0
         SubPlan 2
           ->  Aggregate  (cost=19.74..19.75 rows=1 width=32) (actual time=0.027..0.027 rows=1 loops=21)
                 ->  Nested Loop  (cost=16.23..19.73 rows=1 width=58) (actual time=0.008..0.008 rows=1 loops=21)
                       ->  Index Scan using external_service_repos_repo_id_external_service_id_unique on external_service_repos esr  (cost=0.43..2.65 rows=1 width=51) (actual time=0.003..0.004 rows=1 loops=21)
                             Index Cond: (repo_id = repo.id)
                       ->  Bitmap Heap Scan on external_services svcs  (cost=15.80..16.91 rows=1 width=15) (actual time=0.002..0.002 rows=1 loops=21)
                             Recheck Cond: (id = esr.external_service_id)
                             Filter: (deleted_at IS NULL)
                             Heap Blocks: exact=21
                             ->  Bitmap Index Scan on external_services_pkey  (cost=0.00..15.80 rows=1 width=0) (actual time=0.001..0.001 rows=1 loops=21)
                                   Index Cond: (id = esr.external_service_id)
 Planning Time: 4.087 ms
 Execution Time: 3.288 ms
(25 rows)
Second query, indexed: 6.568 ms ``` QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=1851.06..2301.96 rows=21 width=700) (actual time=5.623..6.331 rows=21 loops=1) -> Result (cost=1851.06..16086.60 rows=663 width=700) (actual time=5.622..6.325 rows=21 loops=1) -> Sort (cost=1851.06..1852.72 rows=663 width=636) (actual time=5.515..5.524 rows=21 loops=1) Sort Key: gr.repo_size_bytes DESC Sort Method: top-N heapsort Memory: 55kB -> Nested Loop (cost=1.11..1833.18 rows=663 width=636) (actual time=0.047..5.090 rows=406 loops=1) -> Index Scan using erik_test_remove6 on repo (cost=0.56..2.78 rows=660 width=628) (actual time=0.030..1.752 rows=406 loops=1) Index Cond: ((lower((name)::text) >= 'github.com/sourceg'::text) AND (lower((name)::text) < 'github.com/sourceh'::text)) Filter: (lower((name)::text) ~~ 'github.com/sourceg%'::text) -> Index Scan using gitserver_repos_pkey on gitserver_repos gr (cost=0.56..2.77 rows=1 width=12) (actual time=0.007..0.007 rows=1 loops=406) Index Cond: (repo_id = repo.id) SubPlan 1 -> Aggregate (cost=1.70..1.71 rows=1 width=32) (actual time=0.010..0.010 rows=1 loops=21) -> Index Only Scan using repo_kvps_pkey on repo_kvps (cost=0.43..1.67 rows=8 width=42) (actual time=0.009..0.009 rows=0 loops=21) Index Cond: (repo_id = repo.id) Heap Fetches: 0 SubPlan 2 -> Aggregate (cost=19.74..19.75 rows=1 width=32) (actual time=0.025..0.025 rows=1 loops=21) -> Nested Loop (cost=16.23..19.73 rows=1 width=58) (actual time=0.017..0.019 rows=1 loops=21) -> Index Scan using external_service_repos_repo_id_external_service_id_unique on external_service_repos esr (cost=0.43..2.65 rows=1 width=51) (actual time=0.009..0.010 rows=1 loops=21) Index Cond: (repo_id = repo.id) -> Bitmap Heap Scan on external_services svcs (cost=15.80..16.91 rows=1 width=15) (actual time=0.005..0.005 rows=1 loops=24) Recheck Cond: (id = esr.external_service_id) Filter: (deleted_at IS NULL) Heap Blocks: exact=24 -> Bitmap Index Scan on external_services_pkey (cost=0.00..15.80 rows=1 width=0) (actual time=0.004..0.004 rows=1 loops=24) Index Cond: (id = esr.external_service_id) Planning Time: 2.881 ms Execution Time: 6.568 ms (29 rows) ```

Seems like a win :) 🍾

Not sure if this is right

interface Props extends RouteComponentProps<{}>, TelemetryProps {}

const ORDERING_OPTIONS: OrderedConnectionOrderingOption[] = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Other than that it doesn't support multi-column sort (which might now be a requirement for this page) this LOOKS GOOD.

return (
<div className={styles.orderControl}>
{orderingOptions.map(orderingOption => {
if (orderingOption.type === 'radio') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can remove this branch and add back only if we really need it (not in advance to "be safe")

label: string

/** "radio" or "select" */
type: string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😱

Suggested change
type: string
type: "radio" | "select"

but I think we can drop "radio"?

@vdavid

vdavid commented Nov 17, 2022

Copy link
Copy Markdown
Contributor Author

OMG this PR just got so much lighter.

After going through all the hassle of adding a new way to order items, I realized that the filter part accepted arrays of items!

When doing the change @philipp-spiess suggested, I went through a bunch of "find usages" searches, when this usage of the component caught my eye, where the filter is used for ordering. Turns out it was possible all along, and hardly any front-end changes were needed. 🤦

As much as I've got attached to my beautiful code, the front-end part of it is plain redundant (the original solution is pretty much pixel perfectly the same as my additional solution), so I've reverted the whole thing.
I've kept the renames where the new naming seems more accurate, but that's it.

If CI passes, I'm quite confident to merge this despite any Chromium issues because this is basically a backend-only change now.

map(searchParams => new URLSearchParams(searchParams)),
map(searchParams => getFilterFromURL(searchParams, this.props.filters)),
map((searchParams: URLSearchParams) => ({
newFilterValues: getFilterFromURL(searchParams, this.props.filters),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why does this have to be an object now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It doesn't. Reverted that, too.

@vdavid vdavid enabled auto-merge (squash) November 17, 2022 15:33
@vdavid vdavid merged commit fb922dd into main Nov 17, 2022
@vdavid vdavid deleted the dv/sortable-repos branch November 17, 2022 15:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants