mirror of https://github.com/perkeep/perkeep.git
corpus: respect more attributes when looking up permanode's time
Change-Id: I2ed9f9f100109510c1617e465a8d3e2b3261d244
This commit is contained in:
parent
1ff2918602
commit
31c324c206
|
@ -33,6 +33,7 @@ import (
|
||||||
"camlistore.org/pkg/context"
|
"camlistore.org/pkg/context"
|
||||||
"camlistore.org/pkg/osutil"
|
"camlistore.org/pkg/osutil"
|
||||||
"camlistore.org/pkg/schema"
|
"camlistore.org/pkg/schema"
|
||||||
|
"camlistore.org/pkg/schema/nodeattr"
|
||||||
"camlistore.org/pkg/sorted"
|
"camlistore.org/pkg/sorted"
|
||||||
"camlistore.org/pkg/strutil"
|
"camlistore.org/pkg/strutil"
|
||||||
"camlistore.org/pkg/syncutil"
|
"camlistore.org/pkg/syncutil"
|
||||||
|
@ -856,31 +857,18 @@ var (
|
||||||
errNoNodeAttr = errors.New("attribute not found")
|
errNoNodeAttr = errors.New("attribute not found")
|
||||||
)
|
)
|
||||||
|
|
||||||
// typeSpecificNodeTimeLocked returns the time that is set as a specific permanode attribute.
|
func (c *Corpus) pnTimeAttrLocked(pn blob.Ref, attr string) (t time.Time, ok bool) {
|
||||||
// That attribute, if any, depends on the nodeType ("camliNodeType" attribute) value, which
|
if v := c.PermanodeAttrValueLocked(pn, attr, time.Time{}, blob.Ref{}); v != "" {
|
||||||
// may be empty as well.
|
if t, err := time.Parse(time.RFC3339, v); err == nil {
|
||||||
func (c *Corpus) typeSpecificNodeTimeLocked(nodeType string, pn blob.Ref) (t time.Time, err error) {
|
return t, true
|
||||||
attr := ""
|
}
|
||||||
switch nodeType {
|
|
||||||
case "foursquare.com:checkin":
|
|
||||||
attr = "startDate"
|
|
||||||
case "twitter.com:tweet":
|
|
||||||
attr = "startDate"
|
|
||||||
// TODO(mpl): other nodeTypes from importers
|
|
||||||
default:
|
|
||||||
return t, errUnsupportedNodeType
|
|
||||||
}
|
}
|
||||||
timeStr := c.PermanodeAttrValueLocked(pn, attr, time.Time{}, blob.Ref{})
|
return
|
||||||
if timeStr == "" {
|
|
||||||
return t, errNoNodeAttr
|
|
||||||
}
|
|
||||||
return time.Parse(time.RFC3339, timeStr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PermanodeTimeLocked returns the time of the content in permanode.
|
// PermanodeTimeLocked returns the time of the content in permanode.
|
||||||
func (c *Corpus) PermanodeTimeLocked(pn blob.Ref) (t time.Time, ok bool) {
|
func (c *Corpus) PermanodeTimeLocked(pn blob.Ref) (t time.Time, ok bool) {
|
||||||
// TODO(bradfitz): keep this time property cached on the permanode / files
|
// TODO(bradfitz): keep this time property cached on the permanode / files
|
||||||
|
|
||||||
// TODO(bradfitz): finish implmenting all these
|
// TODO(bradfitz): finish implmenting all these
|
||||||
|
|
||||||
// Priorities:
|
// Priorities:
|
||||||
|
@ -893,30 +881,34 @@ func (c *Corpus) PermanodeTimeLocked(pn blob.Ref) (t time.Time, ok bool) {
|
||||||
// -- File modtime
|
// -- File modtime
|
||||||
// -- camliContent claim set time
|
// -- camliContent claim set time
|
||||||
|
|
||||||
// First check the type-specific time (e.g. from importers)
|
if t, ok = c.pnTimeAttrLocked(pn, nodeattr.StartDate); ok {
|
||||||
nodeType := c.PermanodeAttrValueLocked(pn, "camliNodeType", time.Time{}, blob.Ref{})
|
|
||||||
if nodeType != "" {
|
|
||||||
if t, err := c.typeSpecificNodeTimeLocked(nodeType, pn); err == nil {
|
|
||||||
return t, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise check time from the FileInfo
|
|
||||||
ccRef, ccTime, ok := c.pnCamliContentLocked(pn)
|
|
||||||
if !ok {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if t, ok = c.pnTimeAttrLocked(pn, nodeattr.DateCreated); ok {
|
||||||
fi, ok := c.files[ccRef]
|
return
|
||||||
if ok {
|
|
||||||
if fi.Time != nil {
|
|
||||||
return time.Time(*fi.Time), true
|
|
||||||
}
|
|
||||||
if fi.ModTime != nil {
|
|
||||||
return time.Time(*fi.ModTime), true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ccTime, true
|
var fi camtypes.FileInfo
|
||||||
|
ccRef, ccTime, ok := c.pnCamliContentLocked(pn)
|
||||||
|
if ok {
|
||||||
|
fi, _ = c.files[ccRef]
|
||||||
|
}
|
||||||
|
if fi.Time != nil {
|
||||||
|
return time.Time(*fi.Time), true
|
||||||
|
}
|
||||||
|
|
||||||
|
if t, ok = c.pnTimeAttrLocked(pn, nodeattr.DatePublished); ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if t, ok = c.pnTimeAttrLocked(pn, nodeattr.DateModified); ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if fi.ModTime != nil {
|
||||||
|
return time.Time(*fi.ModTime), true
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
return ccTime, true
|
||||||
|
}
|
||||||
|
return time.Time{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// PermanodeAnyTimeLocked returns the time that best qualifies the permanode.
|
// PermanodeAnyTimeLocked returns the time that best qualifies the permanode.
|
||||||
|
|
Loading…
Reference in New Issue