Use state for the last_optimize value.

Using config for this kind of data is wrong and it was broken because it didn't call save.

I think there is more similar stuff in the module right now, where it is changing config on a regular basis, but that can be fixed separately.