
Originally Posted by
W00dL3cs
You are making a great work!
May I suggest you the use of LINQ?
Loops are faster than Linq. :) (I sometimes use Linq)
I made a Pathfinder with Linq :) (In Tazqon I use A*)
I am using WeakSQLCache (Only for searching and showing up) for Rooms dat dont change untill they are going to be changed( info)
NO LONGER SQL-FLOOD FOR NAVIGATOR!
Saving Power using (WEAKSQL)
Code:
// 1e request (character) (2 characters) (offline users)
(25-3-2012 21:41:26) SELECT * FROM character_messenger_groups WHERE character_id = @id
(25-3-2012 21:41:26) SELECT character_id,friend_id FROM character_friends WHERE character_id = @id AND pending = '0' OR friend_id = @id AND pending = '0'
(25-3-2012 21:41:26) SELECT * FROM characters WHERE id = @id LIMIT 1
(25-3-2012 21:41:26) SELECT rank FROM characters WHERE id = @id LIMIT 1
(25-3-2012 21:41:26) SELECT * FROM characters WHERE id = @id LIMIT 1
(25-3-2012 21:41:26) SELECT rank FROM characters WHERE id = @id LIMIT 1
// 2e request (same characters)
(25-3-2012 21:41:59) SELECT * FROM character_messenger_groups WHERE character_id = @id
(25-3-2012 21:41:59) SELECT character_id,friend_id FROM character_friends WHERE character_id = @id AND pending = '0' OR friend_id = @id AND pending = '0'
(25-3-2012 21:41:59) SELECT rank FROM characters WHERE id = @id LIMIT 1
(25-3-2012 21:41:59) SELECT rank FROM characters WHERE id = @id LIMIT 1
ROOMMANAGER
Code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Tazqon.Commons.Adapters;
using Tazqon.Storage.Querys;
namespace Tazqon.Habbo.Rooms
{
class RoomManager
{
/// <summary>
/// Storage of the models of rooms.
/// </summary>
public Dictionary<int, RoomModel> Models { get; private set; }
/// <summary>
/// Storage of progressing rooms.
/// </summary>
public Dictionary<int, RoomAdapter> Adapters { get; private set; }
/// <summary>
/// Cache to buffer some sql data in.
/// </summary>
public Dictionary<int, Room> WeakSQLCache { get; private set; }
public RoomManager()
{
Models = new Dictionary<int, RoomModel>();
Adapters = new Dictionary<int, RoomAdapter>();
WeakSQLCache = new Dictionary<int, Room>();
foreach (DataRow Row in System.MySQLManager.GetObject(new RoomModelsQuery()).GetOutput<DataTable>().Rows)
{
RoomModel Model = new RoomModel(Row);
if (!Models.ContainsKey(Model.Id))
{
Models.Add(Model.Id, Model);
}
}
}
public RoomModel GetModel(int Id)
{
using (DictionaryAdapter<int, RoomModel> DA = new DictionaryAdapter<int, RoomModel>(Models))
{
return DA.TryPopValue(Id);
}
}
public Room GetRoom(int RoomId)
{
RoomAdapter Adapter;
Room Room;
if (!Adapters.TryGetValue(RoomId, out Adapter))
{
if (!WeakSQLCache.TryGetValue(RoomId, out Room))
{
Room = new Room(System.MySQLManager.GetObject(new RoomInfoQuery(RoomId)).GetOutput<DataRow>());
WeakSQLCache.Add(RoomId, Room);
}
}
else Room = Adapter.Information;
return Room;
}
public RoomAdapter CastAdapter(int RoomId)
{
RoomAdapter Adapter;
if (!Adapters.TryGetValue(RoomId, out Adapter))
{
Adapter = new RoomAdapter(GetRoom(RoomId));
Adapters.Add(Adapter.Information.Id, Adapter);
if (WeakSQLCache.ContainsKey(RoomId))
{
WeakSQLCache.Remove(RoomId);
}
}
return Adapter;
}
public void DisposeAdapter(RoomAdapter Adapter)
{
if (!WeakSQLCache.ContainsKey(Adapter.Information.Id))
{
WeakSQLCache.Add(Adapter.Information.Id, Adapter.Information);
}
else WeakSQLCache[Adapter.Information.Id] = Adapter.Information;
Adapters.Remove(Adapter.Information.Id);
Adapter.Dispose();
}
public ICollection<Room> GetRooms(int CharacterId)
{
ICollection<Room> Output = new List<Room>();
foreach(DataRow Row in System.MySQLManager.GetObject(new RoomsQuery(CharacterId)).GetOutput<DataTable>().Rows)
{
using (RowAdapter Adapter = new RowAdapter(Row))
{
Room Room = GetRoom(Adapter.PopInt32("id"));
Output.Add(Room);
}
}
return Output;
}
}
enum NavigatorTab
{
PRIVATE_ITEMS = 1, RATED_ITEMS = 2, MY_RAND_FRIENDS = 3, MY_ALIVE_FRIENDS = 4,
MY_ITEMS = 5, MY_FAV_ITEMS = 6, MY_VISITED_ITEMS = 7, SEARCHED_ITEMS = 8
}
}
UPDATED GITHUB: 25-3-2012 21:57 (UTC +1)