Bug - Fixed Store Manager "save prices" fails with lots of items in store

lostcalpolydude

Developer
Staff member
I've got some code working locally. I assume it will solve the issue for stores with a million items stocked, since it only sends prices for repriced items, though I can't actually test that.

The main reason I haven't committed the new code is that updating prices no longer updates everything in the store. The only way to do that with my current code is to close and reopen the Store Manager. I tried to add a "refresh" button, but I don't know how to add a third button there without starting from scratch (using a different type of Panel for StoreManagerPanel, I think), and I didn't really want to get into that. Replacing the auto reprice button would be trivial, but I expect someone would be upset about losing that button.
 

lostcalpolydude

Developer
Staff member
Code:
	public static final void updateSomePrices( String storeText )
	{
		int startIndex = storeText.indexOf( "<!-- U:{" );
		if ( startIndex == -1 ) return;
		startIndex += 7;
		int endIndex = storeText.indexOf( "-->", startIndex );
		if ( endIndex == -1 ) return;

		storeText = storeText.substring( startIndex, endIndex );

		JSONObject json;
		try
		{
			json = new JSONObject( storeText );

			String[] itemDescs = JSONObject.getNames( json );

			for ( String itemDesc : itemDescs )
			{
				int itemId = ItemDatabase.getItemIdFromDescription( itemDesc );
				JSONObject item = json.getJSONObject( itemDesc );
				int newPrice = item.getInt( "price" );
				RequestLogger.printLine( "Price: " + newPrice );
				int newLimit = item.getInt( "lim" );

				SoldItem soldItem = new SoldItem( itemId, 0, 0, 0, 0 );
				int index = StoreManager.soldItemList.indexOf( soldItem );
				int sortedIndex = StoreManager.sortedSoldItemList.indexOf( soldItem );
				soldItem = soldItemList.get( index );
				int quantity = soldItem.getQuantity();
				int lowest = soldItem.getLowest();
				soldItem = new SoldItem( itemId, quantity, newPrice, newLimit, lowest );
				StoreManager.soldItemList.set( index, soldItem );
				StoreManager.sortedSoldItemList.set( sortedIndex, soldItem );
			}
		}
		catch ( JSONException e )
		{
			RequestLogger.printLine( "JSON failure while updating prices." );
			return;
		}
	}
That's a function I added to StoreManager to parse the response from backoffice.php. I never did sort out the GUI stuff (I finally figured out how to add a button, but it looked bad enough that not having it would have been better), so I'm reverting my local code and just posting this if anyone else wants to give it a try.
 

Slashor

New member
Store Manager can't reprice lots of items

I have just added a solid number of items to my store. I go to reprice them and get the error below. I have 1563 items in my store.

Unexpected error, debug log printed.
class java.lang.StringIndexOutOfBoundsException: String index out of range: -21
java.lang.StringIndexOutOfBoundsException: String index out of range: -21
at java.lang.String.substring(Unknown Source)
at net.sourceforge.kolmafia.session.StoreManager.update(StoreManager.java:219)
at net.sourceforge.kolmafia.request.ManageStoreRequest.managePrices(ManageStoreRequest.java:212)
at net.sourceforge.kolmafia.request.ManageStoreRequest.run(ManageStoreRequest.java:167)
at net.sourceforge.kolmafia.RequestThread.postRequest(RequestThread.java:286)
at net.sourceforge.kolmafia.RequestThread.postRequest(RequestThread.java:249)
at net.sourceforge.kolmafia.session.StoreManager.priceItemsAtLowestPrice(StoreManager.java:884)
at net.sourceforge.kolmafia.swingui.StoreManageFrame$StoreManagePanel.actionCancelled(StoreManageFrame.java:338)
at net.sourceforge.kolmafia.swingui.panel.GenericPanel$CancelledListener.execute(GenericPanel.java:640)
at net.sourceforge.kolmafia.swingui.listener.ThreadedListener.run(ThreadedListener.java:239)
at net.sourceforge.kolmafia.RequestThread$SequencedRunnable.run(RequestThread.java:418)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
 

lostcalpolydude

Developer
Staff member
17173. I repurposed the second button on that frame to be refresh. There's undercut (or reprice) CLI commands available.
 
Last edited:

Bale

Minion
Thankyouthankyou! Thank you! I just tested this and it worked fine. I didn't even need that refresh button.

This helps me sooo much.
 

fronobulax

Developer
Staff member
I just assumed it was OCD malling things that won't ever actually sell...

ManageStore will pull and autosell items it thinks will never sell from the mall. At one time it actually would change the OCD entry for such items so that they would always be autosold by OCD. But I was eventually convinced that level of coordination with OCD was not desirable and potentially difficult to maintain so the feature is no more.
 
Top