Skip to content

Commit

Permalink
Remove unused model: garage
Browse files Browse the repository at this point in the history
  • Loading branch information
U-lis committed Oct 16, 2024
1 parent 9c91f1f commit 18bb7c4
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 132 deletions.
74 changes: 0 additions & 74 deletions common/utils/garage.py

This file was deleted.

6 changes: 0 additions & 6 deletions iap/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from common.enums import Store, ReceiptStatus
from common.models.receipt import Receipt
from common.utils.garage import update_iap_garage
from common.utils.google import update_google_price
from iap import settings
from iap.dependencies import session
Expand Down Expand Up @@ -37,11 +36,6 @@ def update_price(store: Store, sess=Depends(session)):
return f"{updated_price_count} prices in {updated_product_count} products are updated."


@router.get("/update-garage")
def update_garage(sess=Depends(session)):
return update_iap_garage(sess)


@router.get("/refunded", response_model=List[RefundedReceiptSchema])
def fetch_refunded(
start: Annotated[
Expand Down
52 changes: 1 addition & 51 deletions iap/api/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
from typing import Dict

import requests
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy import desc, select
from sqlalchemy.exc import NoResultFound
from sqlalchemy.orm import Session
from fastapi import APIRouter, HTTPException
from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR

from common import logger
from common.consts import HOST_LIST
from common.models.garage import GarageActionHistory
from iap.dependencies import session

router = APIRouter(
prefix="/history",
Expand Down Expand Up @@ -101,48 +96,3 @@ def sync_block(block_data):

logger.info("=" * 32)
logger.info(f"{cnt} actions are processed")


@router.get("/sync")
def sync_block_history(start: int = None, end: int = None, limit: int = 100, sess: Session = Depends(session)):
tip_query = """query { blockQuery { blocks(desc: true limit: 1) { index } } }"""
resp = request(EXPLORER_URL, {"query": tip_query})
tip = resp["data"]["blockQuery"]["blocks"][0]["index"]

if end is None:
end = tip

if start is None:
# Start from last block on DB
try:
last_block = sess.execute(
select(GarageActionHistory).order_by(desc(GarageActionHistory.block_index))
).scalars().one()
except NoResultFound:
last_block = None

if not last_block:
start = end - limit

logger.info(f"{start} ~ {end}, limit {limit}")

query = f"""
query {{ blockQuery {{ blocks(desc: true offset: {tip - start} limit: {limit}) {{
hash index timestamp transactions {{ id signer timestamp actions {{ json }} }}
}} }} }}
"""
resp = request(EXPLORER_URL, {"query": query})

block_list = resp["data"]["blockQuery"]["blocks"]
logger.info(f"{len(block_list)} blocks are fetched")
if len(block_list) == 0:
msg = f"No block containing transactions found between {start} and {end}"
logger.warning(msg)
return msg

for block in block_list:
sync_block(block)

result = f"{len(block_list)} blocks synced: from {block_list[-1]['index']} to {block_list[0]['index']}"
logger.info(result)
return result
2 changes: 1 addition & 1 deletion iap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

from common import logger
from common.enums import ReceiptStatus
from common.models.mileage import Mileage
from common.models.product import Product
from common.models.receipt import Receipt
from common.utils.receipt import PlanetID
from iap import settings
from models.mileage import Mileage


def get_purchase_history(sess, planet_id: PlanetID, address: str, product: Optional[Product] = None,
Expand Down

0 comments on commit 18bb7c4

Please sign in to comment.