Skip to content

Commit

Permalink
Fix isaacs/npm#1563 Use latest version, rather than modified time
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Oct 17, 2011
1 parent 2a3e060 commit d2c855d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions registry/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ ddoc.lists.rss = function (head, req) {
if (!row.value || !row.value["dist-tags"]) continue

var doc = row.value
var date = doc.time && doc.time.modified || doc.ctime
if (!date) continue
date = new Date(date)
var authors = doc.maintainers.map(function (m) {
return '<author>' + m.name + '</author>'
}).join('\n ')

doc = doc.versions[doc["dist-tags"].latest]
if (!doc) continue
var latest = doc["dist-tags"].latest
var time = doc.time && doc.time[latest]
var date = new Date(time)
doc = doc.versions[latest]
if (!doc || !time || !date) continue

var url = doc.homepage
, repo = doc.repository || doc.repositories
Expand Down Expand Up @@ -386,7 +386,11 @@ ddoc.views.listAll = {

ddoc.views.modified = { map: modifiedTimeMap }
function modifiedTimeMap (doc) {
var t = new Date(doc.time && doc.time.modified || doc.mtime || 0)
if (!doc.versions) return
var latest = doc["dist-tags"].latest
if (!doc.versions[latest]) return
var time = doc.time && doc.time[latest] || 0
var t = new Date(time)
emit(t.getTime(), doc)
}

Expand Down
6 changes: 5 additions & 1 deletion www/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ function dependencies (doc) {
ddoc.views =
{ search: { map: packageSearch }
, dependencies: {map: dependencies, reduce:"_count"}
, updated: {map: function (doc) {if (doc.time && doc.time.modified) emit(doc.time.modified, 1) }}
, updated: {map: function (doc) {
var l = doc["dist-tags"].latest
, t = doc.time && doc.time[t]
if (t) emit(t, 1)
}}
, tags:
{ map: function (doc) {
if (doc['dist-tags'] && doc['dist-tags'].latest) {
Expand Down

0 comments on commit d2c855d

Please sign in to comment.