Github user iilyak commented on a diff in the pull request:
https://github.com/apache/couchdb-couch/pull/239#discussion_r106263970
--- Diff: src/couch_lru.erl ---
@@ -16,48 +16,57 @@
-include_lib("couch/include/couch_db.hrl").
new() ->
- {gb_trees:empty(), dict:new()}.
-
-insert(DbName, {Tree0, Dict0}) ->
- Lru = erlang:now(),
- {gb_trees:insert(Lru, DbName, Tree0), dict:store(DbName, Lru, Dict0)}.
-
-update(DbName, {Tree0, Dict0}) ->
- case dict:find(DbName, Dict0) of
- {ok, Old} ->
- New = erlang:now(),
- Tree = gb_trees:insert(New, DbName, gb_trees:delete(Old, Tree0)),
- Dict = dict:store(DbName, New, Dict0),
- {Tree, Dict};
- error ->
- % We closed this database before processing the update. Ignore
- {Tree0, Dict0}
+ Updates = ets:new(couch_lru_updates, [ordered_set]),
+ Dbs = ets:new(couch_lru_dbs, [set]),
+ {0, Updates, Dbs}.
+
+insert(DbName, {Count, Updates, Dbs}) ->
+ update(DbName, {Count, Updates, Dbs}).
+
+update(DbName, {Count, Updates, Dbs}) ->
--- End diff --
This possibly could be replaced with:
```
case ets:update_counter(Dbs, DbName, 1, {DbName, Count}) of
Count ->
true = ets:insert(Updates, {{Count, DbName}});
NewCount ->
true = ets:delete(Updates, {NewCount - 1, DbName}),
true = ets:insert(Updates, {{Count, DbName}})
end,
{Count +1, Updates, Dbs}.
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---