conversions: Make NEXT_ID a true singleton.

We now instantiate NEXT_ID in sequencer.py, which avoids
having multiple modules make multiple copies of a sequencer
and possibly causing id collisions.
This commit is contained in:
Steve Howell
2018-10-23 19:38:37 +00:00
committed by showell
parent a2767df51d
commit 50f76e58ce
3 changed files with 14 additions and 9 deletions

View File

@@ -40,10 +40,7 @@ from zerver.data_import.import_util import (
from zerver.data_import.hipchat_attachment import AttachmentHandler
from zerver.data_import.hipchat_user import UserHandler
from zerver.data_import.sequencer import sequencer
# Create one sequencer for our entire conversion.
NEXT_ID = sequencer()
from zerver.data_import.sequencer import NEXT_ID
# stubs
ZerverFieldsT = Dict[str, Any]

View File

@@ -9,10 +9,7 @@ from zerver.data_import.import_util import (
from typing import Any, Dict, List, Optional
from zerver.data_import.sequencer import sequencer
# Create one sequencer for our entire conversion.
NEXT_ID = sequencer()
from zerver.data_import.sequencer import NEXT_ID
class AttachmentHandler:
def __init__(self) -> None:

View File

@@ -26,7 +26,7 @@ def sequencer() -> Callable[[str], int]:
Use like this:
NEXT_ID = sequencer()
message_id = NEXT_ID('message_id')
message_id = NEXT_ID('message')
'''
seq_dict = dict() # type: Dict[str, Callable[[], int]]
@@ -37,3 +37,14 @@ def sequencer() -> Callable[[str], int]:
return seq()
return next_one
'''
NEXT_ID is a singleton used by an entire process, which is
almost always reasonable. If you want to have two parallel
sequences, just use different `name` values.
This object gets created once and only once during the first
import of the file.
'''
NEXT_ID = sequencer()