Exemplo n.º 1
0
 def get_지번_address(self):
     juso_res_json = self._juso_res_json
     if len(juso_res_json["results"]["juso"]) > 1:
         file_log(
             "2개 이상의 지번 주소가 검색되었습니다. 검색 결과 중 첫번째 지번 주소가 임의로 선택되었습니다. : {}".
             format(self.address))
     return juso_res_json["results"]["juso"][0]["jibunAddr"]
Exemplo n.º 2
0
 def get_road_name(self):
     juso_res_json = self._juso_res_json
     rn_list = [data["rn"] for data in juso_res_json["results"]["juso"]]
     if len(set(rn_list)) > 1:
         file_log(
             "2개 이상의 도로가 검색되었습니다. 검색 결과 중 첫번째 도로가 임의로 선택되었습니다. : {}".format(
                 self.address))
     return juso_res_json["results"]["juso"][0]["rn"]
Exemplo n.º 3
0
 def do(self):
     cls_name = self.__class__.__name__
     file_log("{} start : {}".format(cls_name, self.path or ""))
     with WriterContext(self.path) as f:
         self.f = f
         self._do()
     file_log("{} end ({}) : {}".format(cls_name, self.count, self.path
                                        or ""))
Exemplo n.º 4
0
    def _fetch_all(self):
        # 트랜잭션 밖인 경우 혹은 ModelIterate 가 아닌 경우 : DjangoQuerySet 과 동일하게
        tran = self.tran
        if not tran or not issubclass(self._iterable_class, ModelIterable):
            self._super_fetch_all()
            return

        self.assert_transaction()
        assert self.check_required_filters()

        # fetch_all() 이 이미 실행된 경우
        if self._result_cache is not None:
            self._super_fetch_all()
            return

        # key == sql
        try:
            qs = self._chain()
            if self.is_ordered_explicitly() and not self.allow_db_sorting():
                qs.query.clear_ordering(force_empty=True)
            sql = qs.sql
        except EmptyResultSet:
            self._result_cache = []
            self._super_fetch_all()
            return

        # read from cache
        assert sql
        if tran.has_query_cache(sql):
            cached = tran.get_query_cache(sql)
            self._result_cache = cached
            assert self._result_cache is not None

        # truncated queryset 처리
        if self._result_cache is None and self.is_ordered_explicitly() and not self.allow_db_sorting():
            qs = self._chain()
            qs.query.clear_ordering(force_empty=True)
            truncated = qs[:MAX_QUERYSET_SIZE]
            truncated._fetch_all()
            assert truncated._result_cache is not None
            self._result_cache = truncated._result_cache
            if len(self) >= MAX_QUERYSET_SIZE:
                if settings.IS_UNIT_TEST:
                    assert False
                else:
                    file_log("id 정렬이 아닌 case 에서 MAX_QUERYSET_SIZE 를 넘는 쿼리 결과가 존재합니다.")
            truncated = None
            qs = None

        # default
        self._super_fetch_all()
        assert self._result_cache is not None

        # 아직 db 로 sync 되지 않고 Transaction Storage 에만 있는 instances 처리
        if tran.is_dirty:
            instances = [
                ins for ins in tran.instances.values() if isinstance(ins, self.model) and ins.status != Status.DELETED
            ]
            tqs = QuerySet(self.model)
            tqs._result_cache = list(instances)
            for _negate, _args, _kwargs in self._filters:
                if _args:
                    # 장고 내부적으로 활용되는 id 로의 조회만 예외 처리
                    # TODO : Q 에 대한 제대로 된 구현
                    if (
                        len(_args) == 1
                        and _args[0].connector == "AND"
                        and len(_args[0].children) == 1
                        and _args[0].children[0][0] == "id"
                    ):
                        _kwargs = dict(_kwargs)
                        _kwargs["id"] = _args[0].children[0][1]
                    else:
                        raise NotImplementedError("Q 에 대한 Transaction Storage 에서의 query 는 아직 미구현 상태입니다.")
                if "status__in" in _kwargs:
                    statuses = _kwargs["status__in"]
                    if Status.NORMAL in statuses:
                        statuses = tuple(set(list(statuses) + [Status.DIRTY, Status.NEW]))
                        _kwargs = dict(_kwargs)
                        _kwargs["status__in"] = statuses
                tqs = tqs._filter_or_exclude(_negate, *_args, **_kwargs)
            assert tqs._result_cache is not None
            self._result_cache = tqs._result_cache
            tqs = None

        # ordering
        ordering_names = self.query.order_by
        if ordering_names:
            qs = QuerySet(self.model)
            qs._result_cache = self._result_cache
            qs = qs.order_by(*ordering_names)
            assert qs._result_cache is not None
            self._result_cache = qs._result_cache
            qs = None

        # limit
        low_mark, high_mark = self.query.low_mark, self.query.high_mark or MAX_QUERYSET_SIZE
        assert high_mark <= MAX_QUERYSET_SIZE
        if low_mark == 0 and high_mark == MAX_QUERYSET_SIZE:
            pass
        else:
            assert self._result_cache is not None
            self._result_cache = self._result_cache[low_mark:high_mark]

        # insert to cache
        tran.set_query_cache(sql, self._result_cache)
Exemplo n.º 5
0
 def do(self):
     logic_name = self.__class__.__name__
     with DurationChecker() as checker:
         result = self._do()
     file_log("{} duration : {}".format(logic_name, checker.duration))
     return result
Exemplo n.º 6
0
 def on_unhandled_exception(self, instance, e):
     if settings.IS_UNIT_TEST:
         raise e
     file_log("{} : error - {}".format(instance, e))