Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong behavior when call Reload on PersonalCacheStruct #24

Open
kybird opened this issue Apr 26, 2017 · 3 comments
Open

Wrong behavior when call Reload on PersonalCacheStruct #24

kybird opened this issue Apr 26, 2017 · 3 comments

Comments

@kybird
Copy link

kybird commented Apr 26, 2017

if you call reload function on PersonalCacheStruct especially entity has ReadWriteDB property

it will re-load data from Database.

and it set value by ReadEntityProperty method in SqlDataReceiver.cs

it call entity's Property function and it fire event NotifyChange event and the value will be added to SyncQueueManager. clearly not expected behavior.

moreover the "ReadEntityProperty" function set value sequencely

each set value fire event and the "not completed setting entity' will be added;

in another word.

if you have some entity like below


[EntityTable]
class someentity
{
    [EntityField(true)]
    public long userID {get;set}
    
    [EntityField(true)]
    public long subkey {get;set}
}

and we have one data from database as below

UserID, subKey
1, 2

now call

PersonalCacheStruct().Reload();

then we will have two DataSyncQueue item

1-0, 1-2

we don't need add this data to DataSyncQueue again. just waste performance

@Jesse1205
Copy link

How about this link Jesse1205/ScutGame@8cc4ab9
can solve your problem?

@kybird
Copy link
Author

kybird commented Apr 27, 2017

this problem will happen when the entity have more than two key..
and you will see log like below.

EntitySync queue key Entity-1-0-0 faild object is null
EntitySync queue key Entity-1-1-0 faild object is null

here is my solution
It delay Notify Event until finish setting data to Entity
anyway i need to check your changes.
thanks for share!!

SqlDataReceiver.cs

 	private T ReadEntityProperty<T>(IDataReader reader, EntityPropertySetFunc<T> setFunc) where T :  new()
 	{
 		T entity = new T();

 		var disableNotify = entity as EntityChangeEvent; //added
 		if (disableNotify != null) disableNotify.DelayNotify(); //added
 		var columns = _schema.GetColumns();
 		foreach (var column in columns)
 		{
 			try
 			{
 				object fieldValue = reader[column.Name];
 				if (setFunc != null) setFunc(entity, column, fieldValue);
 			}
 			catch (Exception ex)
 			{
 				throw new Exception(string.Format("read {0} table's {1} column error.", _schema.EntityName, column.Name), ex);
 			}
 		}
 		if (disableNotify != null) disableNotify.TriggerNotify(); //added 
 		return entity;
 	}

@kybird
Copy link
Author

kybird commented Apr 27, 2017

@Jesse1205 Can you describe the problem that apply your solution?

i test original TryGetCacheItem. and its lazy anonymous delegate never executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants