I don't think the historyId
for the message list of one specific user is guaranteed to be monotonically increasing.
After I checked my database containing a few gmail users' metadata. I found there is no evidence showing the historyId
is monotonically increasing.
Here is part of the historyId
and internalDate
from my gmail data.
> db.gmail_threads.find({integrationEmail: 'me@test.com'}, {_id:0,historyId:1, internalDate:1, date:1}).limit(500).sort({internalDate:1})
{ "historyId" : "4745", "date" : "Sun, 11 Sep 2016 02:43:52 -0700 (PDT)", "internalDate" : NumberLong("1473587032000") }
{ "historyId" : "2766", "date" : "Sun, 11 Sep 2016 02:43:57 -0700", "internalDate" : NumberLong("1473587037000") }
{ "historyId" : "2745", "date" : "Sun, 11 Sep 2016 02:43:57 -0700", "internalDate" : NumberLong("1473587037000") }
{ "historyId" : "3116", "date" : "Sun, 11 Sep 2016 02:43:57 -0700", "internalDate" : NumberLong("1473587037000") }
{ "historyId" : "2245", "date" : "Sun, 11 Sep 2016 09:44:31 +0000", "internalDate" : NumberLong("1473587071000") }
{ "historyId" : "2246", "date" : "Sun, 11 Sep 2016 09:44:58 +0000", "internalDate" : NumberLong("1473587098000") }
{ "historyId" : "2254", "date" : "Sun, 11 Sep 2016 09:57:24 +0000", "internalDate" : NumberLong("1473587844000") }
{ "historyId" : "2249", "date" : "Sun, 11 Sep 2016 09:57:31 +0000", "internalDate" : NumberLong("1473587851000") }
{ "historyId" : "2244", "date" : "Sun, 11 Sep 2016 09:57:37 +0000", "internalDate" : NumberLong("1473587857000") }
{ "historyId" : "4749", "date" : "Sun, 11 Sep 2016 09:57:58 +0000", "internalDate" : NumberLong("1473587878000") }
{ "historyId" : "2248", "date" : "Sun, 11 Sep 2016 03:10:57 -0700 (PDT)", "internalDate" : NumberLong("1473588657000") }
{ "historyId" : "3067", "date" : "Sun, 11 Sep 2016 16:21:12 -0700 (PDT)", "internalDate" : NumberLong("1473636072000") }
{ "historyId" : "3026", "date" : "Sun, 11 Sep 2016 16:33:27 -0700 (PDT)", "internalDate" : NumberLong("1473636807000") }
{ "historyId" : "2989", "date" : "Sun, 11 Sep 2016 23:38:35 +0000", "internalDate" : NumberLong("1473637115000") }
{ "historyId" : "5091", "date" : "Sun, 11 Sep 2016 16:42:52 -0700 (PDT)", "internalDate" : NumberLong("1473637372000") }
{ "historyId" : "2322", "date" : "Mon, 12 Sep 2016 01:46:21 -0000", "internalDate" : NumberLong("1473644781000") }
{ "historyId" : "3137", "date" : "Mon, 12 Sep 2016 01:53:24 -0000", "internalDate" : NumberLong("1473645204000") }
{ "historyId" : "2560", "date" : "Sun, 11 Sep 2016 20:17:09 -0700 (PDT)", "internalDate" : NumberLong("1473650229000") }
{ "historyId" : "2678", "date" : "Sun, 11 Sep 2016 22:12:18 -0700 (PDT)", "internalDate" : NumberLong("1473657138000") }
{ "historyId" : "2931", "date" : "Mon, 12 Sep 2016 12:22:54 +0000 (UTC)", "internalDate" : NumberLong("1473682974000") }
Type "it" for more
According to Gmail API documents, here is the limitation:
History records are typically available for at least one week and often longer. However, the time period for which records are available may be significantly less and records may sometimes be unavailable in rare cases. If the startHistoryId supplied by your client is outside the available range of history records, the API returns an HTTP 404 error response. In this case, your client must perform a full sync as described in the previous section.