Message Boards
CounterLocalService does not work properly.
CounterLocalService does not work properly.
New Member Posts: 3 Join Date: 9/8/21 Recent PostsHi
I'm ali and try to understand how counter is working.
As i undertood, counter increment a varialble and retrive value. by default its increment one by one. but we can change step. problem is here. i increase counter number to 80 and at next a call increment method with size =70. basically i should get 150 but in practice i get 180.
i shared my codes on github
https://github.com/a-forghani-y79/7.3ga8
liferay version : 7.3ga8
RE: CounterLocalService does not work properly.
Liferay Master Posts: 591 Join Date: 8/8/14 Recent PostsHi,
The next step is calculated from the last incremented value saved in memory and not the size which is in DB, so you may need reset the counter completely and then set the size as below .
counterLocalService.reset(name);
counterLocalService.reset(name, 80);
counterLocalService.increment(name, 70);
You are getting 180 instead of 150 is because the counter value saved in memory may be 110
RE: CounterLocalService does not work properly.
Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent PostsYou're linking to a full repository with multiple modules, and probably refer to some random class in there.
Please condense your code so much that you can include it in the question, describe the expected vs actual outcome. It's a lot of work to figure out what you do/see/expect otherwise, and you probably want to make answering as easy as possible...
RE: RE: CounterLocalService does not work properly.
New Member Posts: 3 Join Date: 9/8/21 Recent Postshi
if i explain it in simple way:
1- try to deploy module that incloude this component:
so we except this output:
- hi its a test
- new value: 1
- new value: 10
- new value: 80
- new value: 130
-end
but actually we got this:
- hi its a test
- new value: 1
- new value: 10
- new value: 80
- new value: 150
-end
may be liferay has some special mathemathic rules. but as i know 50+80 equals 130. its NOT 150.
RE: CounterLocalService does not work properly.
Liferay Master Posts: 591 Join Date: 8/8/14 Recent PostsAs the counter, by default uses 100 as increment count for DB update , once your incremented value crosses 100 it will create new set of counter values. This is the reason why your getting 150 instead of 130.
If you need contineous counter you can set below value in your portal-ext.properties file.
counter.increment.[$COUNTER_NAME$]=1
In your case,you can use
counter.increment.test=1