Skip to content

Commit

Permalink
Generate only one instance for MongoDownloader (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx authored Jul 10, 2024
1 parent 7a4edce commit 58a78b7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions straxen/storage/mongo_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime
from warnings import warn
import pytz
from typing import Tuple, Dict
from strax import exporter, to_str_tuple
import gridfs
from tqdm import tqdm
Expand Down Expand Up @@ -253,6 +254,15 @@ def upload_single(self, config, abs_path):
class MongoDownloader(GridFsInterface):
"""Class to download files from GridFs."""

_instances: Dict[Tuple, "MongoDownloader"] = {}

def __new__(cls, *args, **kwargs):
key = (args, frozenset(kwargs.items()))
if key not in cls._instances:
cls._instances[key] = super(MongoDownloader, cls).__new__(cls)
cls._instances[key].__init__(*args, **kwargs)
return cls._instances[key]

def __init__(self, store_files_at=None, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down

0 comments on commit 58a78b7

Please sign in to comment.