chathistory: Fix truncated backlog due to timezones

Because msgstore_fs writes logs in localtime, the CHATHISTORY timestamps
(UTC) must be converted to localtime prior to filtering ranges ensure
the right range is sent back to the client.

Prior to this patch, the iteration back from the BEFORE time failed to
load the hours between midnight UTC and midnight localtime in each day's
logged messages. This is because the final time to be considered in a
day's log file (the "start" time) reuses the previous start time's
locale:

    start = time.Date(year, month, day, 0, 0, 0, 0, start.Location()).Add(-1)

By converting the original start and end from the CHATHISTORY commands
to localtime in Load*Time and ListTargets, we ensure we read through
midnight each day.
This commit is contained in:
Alex Karle 2021-10-06 23:39:07 -04:00 committed by Simon Ser
parent 1d56ef19e7
commit 8951760733

View File

@ -383,6 +383,8 @@ func (ms *fsMessageStore) parseMessagesAfter(network *network, entity string, re
} }
func (ms *fsMessageStore) LoadBeforeTime(network *network, entity string, start time.Time, end time.Time, limit int) ([]*irc.Message, error) { func (ms *fsMessageStore) LoadBeforeTime(network *network, entity string, start time.Time, end time.Time, limit int) ([]*irc.Message, error) {
start = start.In(time.Local)
end = end.In(time.Local)
history := make([]*irc.Message, limit) history := make([]*irc.Message, limit)
remaining := limit remaining := limit
tries := 0 tries := 0
@ -406,6 +408,8 @@ func (ms *fsMessageStore) LoadBeforeTime(network *network, entity string, start
} }
func (ms *fsMessageStore) LoadAfterTime(network *network, entity string, start time.Time, end time.Time, limit int) ([]*irc.Message, error) { func (ms *fsMessageStore) LoadAfterTime(network *network, entity string, start time.Time, end time.Time, limit int) ([]*irc.Message, error) {
start = start.In(time.Local)
end = end.In(time.Local)
var history []*irc.Message var history []*irc.Message
remaining := limit remaining := limit
tries := 0 tries := 0
@ -472,6 +476,8 @@ func (ms *fsMessageStore) LoadLatestID(network *network, entity, id string, limi
} }
func (ms *fsMessageStore) ListTargets(network *network, start, end time.Time, limit int) ([]chatHistoryTarget, error) { func (ms *fsMessageStore) ListTargets(network *network, start, end time.Time, limit int) ([]chatHistoryTarget, error) {
start = start.In(time.Local)
end = end.In(time.Local)
rootPath := filepath.Join(ms.root, escapeFilename(network.GetName())) rootPath := filepath.Join(ms.root, escapeFilename(network.GetName()))
root, err := os.Open(rootPath) root, err := os.Open(rootPath)
if err != nil { if err != nil {