@@ -75,14 +75,19 @@ func Update(ctx context.Context, db *sql.DB, client *http.Client, sourcesBase st
7575 }
7676 slog .Info ("appstream snapshot" , "version" , version )
7777
78- accKW := make ( map [ string ][] string )
79- accCat := make (map [string ][] string )
78+ type terms struct { kw , cat [] string }
79+ acc := make (map [string ]* terms )
8080 for _ , repo := range componentRepos {
8181 var components int
82- err := fetchRepoComponents (ctx , client , sourcesBase , version , repo , func (name string , terms IndexTerms ) error {
82+ err := fetchRepoComponents (ctx , client , sourcesBase , version , repo , func (name string , t IndexTerms ) error {
8383 components ++
84- accKW [name ] = append (accKW [name ], terms .Keywords ... )
85- accCat [name ] = append (accCat [name ], terms .Categories ... )
84+ e , ok := acc [name ]
85+ if ! ok {
86+ e = & terms {}
87+ acc [name ] = e
88+ }
89+ e .kw = append (e .kw , t .Keywords ... )
90+ e .cat = append (e .cat , t .Categories ... )
8691 return nil
8792 })
8893 if err != nil {
@@ -91,14 +96,6 @@ func Update(ctx context.Context, db *sql.DB, client *http.Client, sourcesBase st
9196 slog .Info ("appstream components parsed" , "repo" , repo , "components" , components )
9297 }
9398
94- names := make (map [string ]struct {})
95- for k := range accKW {
96- names [k ] = struct {}{}
97- }
98- for k := range accCat {
99- names [k ] = struct {}{}
100- }
101-
10299 tx , err := db .BeginTx (ctx , nil )
103100 if err != nil {
104101 return err
@@ -116,9 +113,9 @@ func Update(ctx context.Context, db *sql.DB, client *http.Client, sourcesBase st
116113 defer func () { _ = stmt .Close () }()
117114
118115 var updated int64
119- for name := range names {
120- kw := dedupeWords (accKW [ name ] )
121- cat := dedupeWords (accCat [ name ] )
116+ for name , e := range acc {
117+ kw := dedupeWords (e . kw )
118+ cat := dedupeWords (e . cat )
122119 if kw == "" && cat == "" {
123120 continue
124121 }
@@ -137,7 +134,7 @@ func Update(ctx context.Context, db *sql.DB, client *http.Client, sourcesBase st
137134 return err
138135 }
139136
140- slog .Info ("appstream fields applied" , "distinct_names" , len (names ), "package_rows" , updated )
137+ slog .Info ("appstream fields applied" , "distinct_names" , len (acc ), "package_rows" , updated )
141138
142139 if _ , err := db .ExecContext (ctx , `INSERT INTO package_fts(package_fts) VALUES('rebuild')` ); err != nil {
143140 return fmt .Errorf ("rebuild fts: %w" , err )
0 commit comments