Skip to content

Commit b6abd00

Browse files
committed
Rename 'new-browse' to 'browse', remove dead search explanation code
1 parent bf43964 commit b6abd00

File tree

9 files changed

+34
-270
lines changed

9 files changed

+34
-270
lines changed

datafiles/static/new-browse.js renamed to datafiles/static/browse.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const d = document;
22

33
const initialParams = new URL(d.location).searchParams;
44
// This parameter is named 'terms' because it is from before filters were
5-
// introduced. But we will parse it a normal search string (including filters)
5+
// introduced. But we will parse it as a normal search string (including filters)
66
const initialSearchQuery = initialParams.has('terms') ? initialParams.get('terms') : ''
77
d.querySelector("#searchQuery").value = initialSearchQuery;
88

@@ -212,9 +212,9 @@ const refresh = async () => {
212212
container.appendChild(createIndexIndicator());
213213
container.appendChild(createPaginator());
214214
if (state.searchQuery.trim() === "") {
215-
d.querySelector("#newBrowseFooter").style.display = "none";
215+
d.querySelector("#browseFooter").style.display = "none";
216216
} else {
217-
d.querySelector("#newBrowseFooter").style.display = "block";
217+
d.querySelector("#browseFooter").style.display = "block";
218218
const url = new URL(hoogleNoParam);
219219
url.searchParams.set("hoogle", state.searchQuery);
220220
d.querySelector("#hoogleLink").setAttribute("href", url);

datafiles/templates/Html/new-browse.html.st renamed to datafiles/templates/Html/browse.html.st

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
width: 50vw;
1010
margin-left: 0;
1111
}
12-
#newBrowse th a {
12+
#browseTable th a {
1313
display:block;
1414
color: inherit;
1515
text-decoration: inherit;
@@ -29,26 +29,26 @@
2929
.commaList li:last-child::after {
3030
content: "";
3131
}
32-
#newBrowse {
32+
#browseTable {
3333
width: 100%;
3434
margin-top: 3em;
3535
}
36-
#newBrowse th, #newBrowse td {
36+
#browseTable th, #browseTable td {
3737
padding: 4px 17px 4px 4px;
3838
}
39-
#newBrowse th {
39+
#browseTable th {
4040
border-bottom: 1px solid #111;
4141
}
42-
#newBrowse th {
42+
#browseTable th {
4343
background-repeat: no-repeat;
4444
background-image: url(/static/images/sort_both.png);
4545
background-position: center right;
4646
padding-right: 0;
4747
}
48-
#newBrowse th.ascending {
48+
#browseTable th.ascending {
4949
background-image: url(/static/images/sort_asc.png);
5050
}
51-
#newBrowse th.descending {
51+
#browseTable th.descending {
5252
background-image: url(/static/images/sort_desc.png);
5353
}
5454
.paginator {
@@ -133,7 +133,7 @@
133133
.lastUpload, #sliderAndOutput {
134134
white-space: nowrap;
135135
}
136-
#newBrowseFooter {
136+
#browseFooter {
137137
display: none;
138138
}
139139
#toggleAdvanced {
@@ -225,7 +225,7 @@
225225
<dd>Only show packages that are available in the Debian distribution. See the <a href="/distros">full list of available distributions</a>.</dd>
226226
</dl>
227227
</div>
228-
<table id=newBrowse class=fancy>
228+
<table id=browseTable class=fancy>
229229
<thead>
230230
<tr>
231231
<th id=arrow-name><a href="javascript: sort('name')">Name</a></th>
@@ -242,7 +242,7 @@
242242
<script type=module>
243243
import { sort, submitSearch, toggleAdvanced, appendDeprecated, appendAgeOfLastUL,
244244
appendTag, appendRating, validateAgeOfLastUL, validateTag }
245-
from "/static/new-browse.js";
245+
from "/static/browse.js";
246246
window.sort = sort;
247247
window.submitSearch = submitSearch;
248248
window.toggleAdvanced = toggleAdvanced;
@@ -255,7 +255,7 @@
255255
</script>
256256
<div id=paginatorContainer>
257257
</div>
258-
<div id=newBrowseFooter>
258+
<div id=browseFooter>
259259
Alternatively, if you are looking for a particular function then try <a href="#" id=hoogleLink target=_blank>Hoogle</a>.
260260
</div>
261261
</div>

src/Distribution/Server/Features.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Distribution.Server.Features.Upload (initUploadFeature)
2121
import Distribution.Server.Features.Mirror (initMirrorFeature)
2222

2323
#ifndef MINIMAL
24-
import Distribution.Server.Features.Browse (initNewBrowseFeature)
24+
import Distribution.Server.Features.Browse (initBrowseFeature)
2525
import Distribution.Server.Features.TarIndexCache (initTarIndexCacheFeature)
2626
import Distribution.Server.Features.Html (initHtmlFeature)
2727
import Distribution.Server.Features.PackageCandidates (initPackageCandidatesFeature, candidatesCoreResource, queryGetCandidateIndex)
@@ -153,8 +153,8 @@ initHackageFeatures env@ServerEnv{serverVerbosity = verbosity} = do
153153
initSitemapFeature env
154154
mkPackageFeedFeature <- logStartup "package feed" $
155155
initPackageFeedFeature env
156-
mkNewBrowseFeature <- logStartup "new browse" $
157-
initNewBrowseFeature env
156+
mkBrowseFeature <- logStartup "browse" $
157+
initBrowseFeature env
158158
mkPackageJSONFeature <- logStartup "package info JSON" $
159159
initPackageInfoJSONFeature env
160160
#endif
@@ -330,7 +330,7 @@ initHackageFeatures env@ServerEnv{serverVerbosity = verbosity} = do
330330
usersFeature
331331
tarIndexCacheFeature
332332

333-
browseFeature <- mkNewBrowseFeature
333+
browseFeature <- mkBrowseFeature
334334
coreFeature
335335
usersFeature
336336
tagsFeature

src/Distribution/Server/Features/Browse.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# LANGUAGE BlockArguments, NamedFieldPuns, TupleSections #-}
2-
module Distribution.Server.Features.Browse (initNewBrowseFeature, PaginationConfig(..), StartIndex(..), NumElems(..), paginate) where
2+
module Distribution.Server.Features.Browse (initBrowseFeature, PaginationConfig(..), StartIndex(..), NumElems(..), paginate) where
33

44
import Control.Arrow (left)
55
import Control.Monad.Except (ExceptT, liftIO, throwError)
@@ -40,8 +40,8 @@ type BrowseFeature =
4040
-> DistroFeature
4141
-> IO HackageFeature
4242

43-
initNewBrowseFeature :: ServerEnv -> IO BrowseFeature
44-
initNewBrowseFeature _env =
43+
initBrowseFeature :: ServerEnv -> IO BrowseFeature
44+
initBrowseFeature _env =
4545
pure \coreFeature userFeature tagsFeature listFeature searchFeature distroFeature ->
4646
pure $
4747
(emptyHackageFeature "json")

src/Distribution/Server/Features/Html.hs

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,13 @@ import Distribution.Package
6060
import Distribution.Version
6161
import Distribution.Text (display)
6262

63-
import Data.Char (toLower)
6463
import Data.List (intercalate, intersperse, insert)
6564
import Data.Function (on)
6665
import qualified Data.Map as Map
6766
import qualified Data.Set as Set
6867
import qualified Data.Vector as Vec
6968
import qualified Data.Text as T
70-
import qualified Data.ByteString.Lazy.Char8 as BS (ByteString, pack)
69+
import qualified Data.ByteString.Lazy.Char8 as BS (ByteString)
7170
import qualified Network.URI as URI
7271

7372
import Text.XHtml.Strict
@@ -129,11 +128,11 @@ initHtmlFeature env@ServerEnv{serverTemplatesDir, serverTemplatesMode,
129128
, "tag-edit.html"
130129
, "candidate-page.html"
131130
, "candidate-index.html"
132-
, "new-browse.html"
131+
, "browse.html"
133132
]
134133

135134

136-
return $ \user@UserFeature{groupChangedHook} core@CoreFeature{packageChangeHook}
135+
return $ \user core@CoreFeature{packageChangeHook}
137136
packages upload
138137
candidates versions
139138
-- [reverse index disabled] reverse
@@ -147,7 +146,7 @@ initHtmlFeature env@ServerEnv{serverTemplatesDir, serverTemplatesMode,
147146
reportsCore
148147
usersdetails -> do
149148
-- do rec, tie the knot
150-
rec let (feature, packageIndex, packagesPage, browseTable) =
149+
rec let (feature, packageIndex, packagesPage) =
151150
htmlFeature env user core
152151
packages upload
153152
candidates versions
@@ -160,7 +159,7 @@ initHtmlFeature env@ServerEnv{serverTemplatesDir, serverTemplatesMode,
160159
reportsCore
161160
usersdetails
162161
(htmlUtilities core candidates tags user)
163-
mainCache namesCache browseCache
162+
mainCache namesCache
164163
templates
165164

166165
-- Index page caches
@@ -178,23 +177,13 @@ initHtmlFeature env@ServerEnv{serverTemplatesDir, serverTemplatesMode,
178177
asyncCacheUpdateDelay = serverCacheDelay,
179178
asyncCacheLogVerbosity = verbosity
180179
}
181-
browseCache <- newAsyncCacheNF browseTable
182-
defaultAsyncCachePolicy {
183-
asyncCacheName = "browse packages",
184-
asyncCacheUpdateDelay = serverCacheDelay,
185-
asyncCacheLogVerbosity = verbosity
186-
}
187180

188181
registerHook itemUpdate $ \_ -> do
189182
prodAsyncCache mainCache "item update"
190183
prodAsyncCache namesCache "item update"
191-
prodAsyncCache browseCache "item update"
192184
registerHook packageChangeHook $ \_ -> do
193185
prodAsyncCache mainCache "package change"
194186
prodAsyncCache namesCache "package change"
195-
prodAsyncCache browseCache "package change"
196-
registerHook groupChangedHook $ \_ -> do
197-
prodAsyncCache browseCache "package change"
198187

199188
return feature
200189

@@ -220,9 +209,8 @@ htmlFeature :: ServerEnv
220209
-> HtmlUtilities
221210
-> AsyncCache Response
222211
-> AsyncCache Response
223-
-> AsyncCache BS.ByteString
224212
-> Templates
225-
-> (HtmlFeature, IO Response, IO Response, IO BS.ByteString)
213+
-> (HtmlFeature, IO Response, IO Response)
226214

227215
htmlFeature env@ServerEnv{..}
228216
user
@@ -232,17 +220,17 @@ htmlFeature env@ServerEnv{..}
232220
-- [reverse index disabled] ReverseFeature{..}
233221
tags download
234222
rank
235-
list@ListFeature{getAllLists, makeItemList}
223+
list@ListFeature{getAllLists}
236224
names
237225
mirror distros
238226
docsCore docsCandidates
239227
tarIndexCache
240228
reportsCore
241229
usersdetails
242230
utilities@HtmlUtilities{..}
243-
cachePackagesPage cacheNamesPage cacheBrowseTable
231+
cachePackagesPage cacheNamesPage
244232
templates
245-
= (HtmlFeature{..}, packageIndex, packagesPage, browseTable)
233+
= (HtmlFeature{..}, packageIndex, packagesPage)
246234
where
247235
htmlFeatureInterface = (emptyHackageFeature "html") {
248236
featureResources = htmlResources
@@ -256,10 +244,6 @@ htmlFeature env@ServerEnv{..}
256244
cacheDesc = "packages page by name",
257245
getCacheMemSize = memSize <$> readAsyncCache cacheNamesPage
258246
}
259-
, CacheComponent {
260-
cacheDesc = "package browse page",
261-
getCacheMemSize = memSize <$> readAsyncCache cacheBrowseTable
262-
}
263247
]
264248
, featurePostInit = syncAsyncCache cachePackagesPage
265249
, featureReloadFiles = reloadTemplates templates
@@ -283,7 +267,6 @@ htmlFeature env@ServerEnv{..}
283267
htmlPreferred
284268
cachePackagesPage
285269
cacheNamesPage
286-
cacheBrowseTable
287270
templates
288271
names
289272
candidates
@@ -430,15 +413,6 @@ htmlFeature env@ServerEnv{..}
430413
]
431414
return htmlpage
432415

433-
browseTable :: IO BS.ByteString
434-
browseTable = do
435-
pkgIndex <- queryGetPackageIndex
436-
let packageNames = sortOn (map toLower . unPackageName) $ Pages.toPackageNames pkgIndex
437-
pkgDetails <- makeItemList packageNames
438-
let rowList = map makeRow pkgDetails
439-
tabledata = "" +++ rowList +++ ""
440-
return . BS.pack . showHtmlFragment $ tabledata
441-
442416
{-
443417
-- Currently unused, mainly because not all web browsers use eager authentication-sending
444418
-- Setting a cookie might work here, albeit one that's stateless for the server, is not
@@ -484,7 +458,6 @@ mkHtmlCore :: ServerEnv
484458
-> HtmlPreferred
485459
-> AsyncCache Response
486460
-> AsyncCache Response
487-
-> AsyncCache BS.ByteString
488461
-> Templates
489462
-> SearchFeature
490463
-> PackageCandidatesFeature
@@ -511,7 +484,6 @@ mkHtmlCore ServerEnv{serverBaseURI, serverBlobStore}
511484
HtmlPreferred{..}
512485
cachePackagesPage
513486
cacheNamesPage
514-
_cacheBrowseTable
515487
templates
516488
SearchFeature{..}
517489
PackageCandidatesFeature{..}
@@ -566,7 +538,7 @@ mkHtmlCore ServerEnv{serverBaseURI, serverBlobStore}
566538

567539
serveBrowsePage :: DynamicPath -> ServerPartE Response
568540
serveBrowsePage _dpath = do
569-
template <- getTemplate templates "new-browse.html"
541+
template <- getTemplate templates "browse.html"
570542
return $ toResponse $ template
571543
[ "heading" $= "Browse and search packages" ]
572544

src/Distribution/Server/Features/Search.hs

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
{-# LANGUAGE RankNTypes, NamedFieldPuns, RecordWildCards, RecursiveDo #-}
1+
{-# LANGUAGE RankNTypes, NamedFieldPuns, RecordWildCards #-}
22
module Distribution.Server.Features.Search (
3-
SearchFeature(..),
3+
SearchFeature(SearchFeature, searchPackages, searchPackagesResource),
44
initSearchFeature,
5-
6-
-- * Search parameters
7-
defaultSearchRankParameters,
8-
SearchEngine.SearchRankParameters(..),
9-
PkgDocField, PkgDocFeatures,
10-
BM25F.Explanation(..),
115
) where
126

137
import Distribution.Server.Framework
@@ -17,9 +11,7 @@ import Distribution.Server.Features.Core
1711
import Distribution.Server.Features.PackageList
1812

1913
import Distribution.Server.Features.Search.PkgSearch
20-
import Distribution.Server.Features.Search.SearchEngine (SearchRankParameters(..))
2114
import qualified Distribution.Server.Features.Search.SearchEngine as SearchEngine
22-
import qualified Distribution.Server.Features.Search.BM25F as BM25F
2315
import qualified Distribution.Server.Packages.PackageIndex as PackageIndex
2416

2517
import Distribution.Server.Packages.Types
@@ -38,13 +30,7 @@ data SearchFeature = SearchFeature {
3830

3931
searchPackagesResource :: Resource,
4032

41-
searchPackages :: forall m. MonadIO m => [String] -> m [PackageName],
42-
searchPackagesExplain :: forall m. MonadIO m
43-
=> SearchRankParameters PkgDocField PkgDocFeatures
44-
-> [String]
45-
-> m (Maybe PackageName,
46-
[(BM25F.Explanation PkgDocField PkgDocFeatures T.Text
47-
,PackageName)])
33+
searchPackages :: forall m. MonadIO m => [String] -> m [PackageName]
4834
}
4935

5036
instance IsHackageFeature SearchFeature where
@@ -156,17 +142,6 @@ searchFeature ServerEnv{serverBaseURI} CoreFeature{..} ListFeature{getAllLists}
156142
let results = SearchEngine.query se (map T.pack terms)
157143
return results
158144

159-
searchPackagesExplain :: MonadIO m
160-
=> SearchRankParameters PkgDocField PkgDocFeatures
161-
-> [String]
162-
-> m (Maybe PackageName, [(BM25F.Explanation PkgDocField PkgDocFeatures T.Text, PackageName)])
163-
searchPackagesExplain params terms = do
164-
se <- readMemState searchEngineState
165-
let results = SearchEngine.queryExplain
166-
(SearchEngine.setRankParams params se)
167-
(map T.pack terms)
168-
return results
169-
170145
handlerGetOpenSearch :: DynamicPath -> ServerPartE Response
171146
handlerGetOpenSearch _ = do
172147
template <- getTemplate templates "opensearch.xml"

0 commit comments

Comments
 (0)