Is it guaranteed that numeric auto-incremented ID of new entity always bigger than existing IDs?

后端 未结 1 1769
囚心锁ツ
囚心锁ツ 2021-01-23 02:40

Is it guaranteed that auto-incremented ID of new entity always bigger than existing IDs ?

Basically I want to periodically dump entity (e.g. Comment) in background task

1条回答
  •  伪装坚强ぢ
    2021-01-23 02:51

    Afaik, no. IDs seem to be allocated in blocks (see here). I've personally seen IDs allocated something like this: 1001, 2001, 1002, 3001, 2002, etc.. It seems that they are incremented contiguously within a block, but there are several blocks used in parallel.

    So you can not rely on this to check for new entities.

    Instead use Query Cursors for this. Create a timestamp property (can be a unix timestamp of type long) on Comment that records when Comment was created. Then use query and cursors to detect new entities.

    0 讨论(0)
提交回复
热议问题