Subversion Repositories SmartDukaan

Rev

Rev 35446 | Rev 35461 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35446 Rev 35447
Line 1516... Line 1516...
1516
        Order order = orders.get(0);
1516
        Order order = orders.get(0);
1517
        float totalAmount = 0;
1517
        float totalAmount = 0;
1518
        int totalQty = 0;
1518
        int totalQty = 0;
1519
        Map<Integer, CartItem> itemIdCartItemMap = new HashMap<>();
1519
        Map<Integer, CartItem> itemIdCartItemMap = new HashMap<>();
1520
 
1520
 
-
 
1521
        // Batch fetch all TagListings by itemIds to avoid N+1 queries
-
 
1522
        Set<Integer> allItemIds = inventoryItems.stream()
-
 
1523
                .map(InventoryItem::getItemId)
-
 
1524
                .collect(Collectors.toSet());
-
 
1525
        List<TagListing> allTagListings = tagListingRepository.selectByItemIdsAndTagIds(allItemIds, null);
-
 
1526
        Map<Integer, TagListing> itemIdTagListingMap = allTagListings.stream()
-
 
1527
                .collect(Collectors.toMap(TagListing::getItemId, t -> t, (u, v) -> u));
-
 
1528
 
1521
        List<CartItem> cartItems = new ArrayList<>();
1529
        List<CartItem> cartItems = new ArrayList<>();
1522
        for (InventoryItem inventoryItem : inventoryItems) {
1530
        for (InventoryItem inventoryItem : inventoryItems) {
1523
            TagListing tagListing = tagListingRepository.selectByItemId(inventoryItem.getItemId());
1531
            TagListing tagListing = itemIdTagListingMap.get(inventoryItem.getItemId());
1524
            long quantity = inventoryItemCountMap.get(inventoryItem.getId());
1532
            long quantity = inventoryItemCountMap.get(inventoryItem.getId());
1525
            totalAmount += inventoryItem.getUnitPrice() * quantity;
1533
            totalAmount += inventoryItem.getUnitPrice() * quantity;
1526
            totalQty += quantity;
1534
            totalQty += quantity;
1527
            if (!itemIdCartItemMap.containsKey(inventoryItem.getItemId())) {
1535
            if (!itemIdCartItemMap.containsKey(inventoryItem.getItemId())) {
1528
                CartItem cartItem = new CartItem();
1536
                CartItem cartItem = new CartItem();